




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
consthooks=['create','activate','update','remove','destroy']exportfunctioncreatePatchFunction(backend){//const{modules,nodeOps}=backendfor(i=0;i<hooks.length;++i){//cbs['update']=cbs[hooks[i]]=//modules:[attrs,klass,events,domProps,style,transition]for(j=0;j<modules.length;++j){//modules[0]['update']是創(chuàng)建屬性執(zhí)行函數(shù),其他hookif(isDef(modules[j][hooks[i]]))}}//cbs['update']:[fn,fn,fn...}functionpatchVnode(...)if(isDef(data)&&isPatchable(vnode))//每次patchfor(i=0;i<cbs.update.length;++i)if(isDef(i=data.hook)&&isDef(i=i.update))i(oldVnode,}}}<div<div//使用elnewdata:{foo:'foo'},el:"#demo",constapp=new//輸出render?unction?unction{with(this)return_c('div',{attrs:{"id":"demo"}},_c('h1',[_v("Vue.js測試_v("_c('p',}} parseHTML(tempalte,{start(tag,attrs,unary){},//遇到開 end(){},//遇到結(jié)束 chars(text){},//遇到文本 comment(text){}//遇到注 代碼實(shí)現(xiàn) piler/optimizer.js-exportexportfunctionoptimize(root: ement,options:{if(!root)isStaticKey=genStaticKeysCached(options.staticKeys||'') Tag=options.is Tag||no////markStaticRoots(root,} exportexportfunction(ast: ement|optionsoptions:):CodegenResultconststate=newconstcode=ast?genElement(ast,state):'_c("div")'return{render:`with(this){return${code}}`,staticRenderFns:state.staticRenderFns}}////解析v-functionprocessIf(el)constexp=getAndRemoveAttr(el,'v-if')//獲取v-if=“exp"中exp并刪除v-ifif(exp)el.if=exp為ast添加ifaddIfCondition(el,{//為ast添加ifConditionsexp:exp,block:else{if(getAndRemoveAttr(el,'v-else')!={el.else=}constelseif=getAndRemoveAttr(el,'v-else-if')if(elseif){el.elseif=}}}functiongenIfConditions(conditions:ASTIfConditions,state:CodegenState,altGen?:Function,altEmpty?:string):stringconstconstconditionconditions.shiftif(condition.exp`(${condition.exp})?${genIfConditions(conditions,state,altGen,}elsereturn}//v-ifwithv-onceshouldgeneratecodelike(a)?_m(0):_m(1)functiongenTernaryExp(el){}} "with(this){return"with(this){return(foo)?_c('h1',[_v(_s(foo))]):_c('h1',[_v("no_v("到這些渲染好的vnodes。對象,著不同名稱的插槽以及它們對應(yīng)的渲染函數(shù),只有在編譯和渲染子組件階段////processSlotContent:處理 tev-constslotBindinggetAndRemoveAttrByRegex(elslotRE)查找v-slot:xxxif(slotBinding){constnamedynamicgetSlotName(slotBindingname是xxxel.slotTarget=name//xxx賦值到slotTargetel.slotTargetDynamic=dynamicel.slotScopeslotBinding.value||emptySlotScopeTokenyyy賦值到}processSlotOutlet:處理if(el.tag==='slot')el.slotName=getBindingAttr(el,'name')//獲取slot的name并賦值到}genScopedSlot:這里把slotScopeconstfn=`function(${slotScope}){``return${el.tag=== ?el.if&&?`(${el.if})?${genChildren(el,state)||:genChildren(el,state)||:genElement(el,//constv-slotwithoutscopeon=slotScope?``:return`{key:${el.slotTarget|| npmrun//vue.config.js//vue.config.jsconstport=7070;consttitle="vue項(xiàng)目最佳實(shí)踐module.exports=publicPath:'/best-practice'部署應(yīng)用包時的基本URLdevServer:{port: ck://向index.htmlname:}//<title><%= ckCnpmnpmisvg-sprite-loader-////resolveconstpath=functionresolve(dir)returnpath.join(dirname,} ck(config)//配置svg規(guī)則排除 //新增icons規(guī)則,設(shè)置svg-sprite-loader處理 中的..rule("icons")//新增icons.test(/\.svg$/)//test.include.add(resolve("src/icons"include.end()//add完上下文是數(shù)組不是icons規(guī)則,使用end().use("svg-sprite-loader")//添加use.loader("svg-sprite-loader")//切換上下文為svg-sprite-.optionssymbolId:"icon-[name]"})//為svg-sprite-loader.end();}//////指定requireconstreq=require.context('./svg',false,////import <svg:class="svgClass"aria-hidden="true"v-<use:xlink:href="iconName" exportdefault{name:'SvgIcon',props:{{type:required:true{type:default:''}{iconName()svgClasssvgClass()if(this.className)return'svg-icon'+}elsereturn'svg-}}}}<style.svg-{width:1em;height:1em;vertical-align:-0.15em;fill:currentColor;overflow:hidden;}importimportVuefromimportSvgIconfromponent('svg-icon',<svg-icon<svg-iconicon-class="qq"></svg-constantRoutes和asyncRoutes。importimportVuefromimportRouterfrom"vue-importLayoutfrom'@/layout'exportconstconstRoutes={path:componentimport("@/views/Login"),hidden:true//導(dǎo)航菜單忽略該項(xiàng){path:component:Layout,//應(yīng)用布局redirect:"/home",children:{path:"home",component:()=>import(/*wckChunkName:"home"*/"@/views/Home.vue"),name:"home",meta:title:"Home"icon:"qq"http://}}]}exportconstasyncRoutes={path:"/about",component:Layout,redirect:"/about/index",children:{path:"index",component:()=>import(/*wckChunkName:"home"*/"@/views/About.vue"),name:"about",meta:title:"About",icon:"qq",roles:['admin',}]}exportdefaultRouter({mode:"history",base:process.env.BASE_URL,routes:constRoutesimportrouterfrom'./router'importstorefrom'./store'import{Message}from'element-import{getToken}from'@/utils/auth'//從獲取令牌constwhiist=['/login']//無需令牌白router.beforeEach(async(to,from,next)=>{//consthasToken=if(hasToken)if(to.path==='/login')//next({path:'/'}else//consthasRoles=store.getters.roles&&store.getters.roles.length0ifnext繼續(xù)即}elsetry//const{roles}=await//constaccessRoutes=awaitstore.dispatch('permission/generateRoutes',roles)//添加這些路由至路由//繼續(xù)路由切換,確保addRoutesnext({...to,rece:true}catch(error)出錯需重置令牌并重新登錄(令牌過期、網(wǎng)絡(luò)錯誤等原因awaitstore.dispatch('user/resetToken')Message.error(error||'HasError')}}}}elseif(whiist.indexOf(to.path)!==-1)//白路由放}}else}}sfromconstToken=exportfunction{exportfunction{return exportfunction{importimportVuefrom'vue'importVuexfrom'vuex'importpermissionfromimportuserfromconststore=newVuex.Store({modules:{permission,exportdefaultimportimport{getToken,setToken,removeToken}fromconststate{token:getToken(),roles:constmutations={SET_TOKEN:(state,token)=>{state.token=SET_ROLES:(state,roles){state.roles=}constactions=//userlogin({commit},{const{username}=userInfo;returnnewPromise((resolve,reject)=>{setTimeout(()=>if(username==="admin"||username==={commit("SET_TOKEN",username);}elsereject("用戶名、錯誤}},//getusergetInfo({commit,state{returnnewPromise((resolve){setTimeout(()=>constroles=state.token==='admin'?['admin']:['editor']commit("SET_ROLES",roles);},//removetokenresetToken({commit}){returnnewPromise(resolve{commit("SET_TOKEN",commit("SET_ROLES",[]);removeToken();resolve();}exportexport{namespaced:true,permission模塊:路由配置信息、路由生成邏輯,import{asyncRoutes,constRoutes}from@roles@routefunctionhasPermission(roles,route)//如果當(dāng)前路由有roles字段則需判斷用戶權(quán)if(route.meta&&route.meta.roles)//若用戶擁有的角色中有被包含在待判定路由角色表中的則擁有returnroles.some(role=>}else//沒有設(shè)置roles則無需判定即可return}}@routes待過濾路由表,首次傳入的就是@rolesexportfunctionfilsyncRoutes(routes,{constres=routes.forEach(route=>//一consttmp={...route//如果用戶有權(quán)則加入結(jié)果路由if(hasPermission(roles,tmp))//if(tmp.children)tmp.children= syncRoutes(tmp.children,}}return}consts
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年企業(yè)正式員工合同簽訂范本
- 2025年網(wǎng)絡(luò)商業(yè)推廣合同
- 實(shí)習(xí)學(xué)生臨時工勞動合同示例(2025年)
- 云計(jì)算資源管理合同2025
- 2025年醫(yī)療機(jī)構(gòu)主治醫(yī)師績效合同范本
- 合同法律風(fēng)險(xiǎn)評估與控制
- 2025年企業(yè)與個人汽車租賃合同樣式
- 2025年教育機(jī)構(gòu)裝具供需合同
- 2025年醫(yī)療診所醫(yī)生合同模板
- 2025年企業(yè)農(nóng)產(chǎn)品供應(yīng)購銷合同
- DL∕T 1084-2021 風(fēng)力發(fā)電場噪聲限值及測量方法
- DL∕T 478-2013 繼電保護(hù)和安全自動裝置通 用技術(shù)條件 正式版
- AQ/T 2036-2011 金屬非金屬地下礦山通信聯(lián)絡(luò)系統(tǒng)建設(shè)規(guī)范 (正式版)
- NB-T33004-2013電動汽車充換電設(shè)施工程施工和竣工驗(yàn)收規(guī)范
- 2024年云南省中考語文真題版,含答案
- DZ∕T 0399-2022 礦山資源儲量管理規(guī)范(正式版)
- 2024年鄂爾多斯市國資產(chǎn)投資控股集團(tuán)限公司招聘公開引進(jìn)高層次人才和急需緊缺人才筆試參考題庫(共500題)答案詳解版
- 競賽試卷(試題)-2023-2024學(xué)年六年級下冊數(shù)學(xué)人教版
- 幼兒園強(qiáng)制報(bào)告制度培訓(xùn)
- 《研學(xué)旅行課程設(shè)計(jì)》課件-辨識與研學(xué)旅行場混淆的概念
- GB/T 43700-2024滑雪場所的運(yùn)行和管理規(guī)范
評論
0/150
提交評論