Vue JS语法求解读

本人刚学JavaScript和VueJs,看Vue官方的Demo发现这样的写法有点吃力,想请教大家这行代码什么含义,或者帮我找个教程我自己学学也行,我不知道这是JS的语法还是ES6什么的新语法,新东东太多太杂。
constcreateListView=id=>()=>import('../views/CreateListView').then(m=>m.default(id))
来自(第7行):https://github.com/vuejs/vue-...
完整代码:
importVuefrom'vue'
importRouterfrom'vue-router'
Vue.use(Router)
//route-levelcodesplitting
constcreateListView=id=>()=>import('../views/CreateListView').then(m=>m.default(id))
constItemView=()=>import('../views/ItemView.vue')
constUserView=()=>import('../views/UserView.vue')
exportfunctioncreateRouter(){
returnnewRouter({
mode:'history',
scrollBehavior:()=>({y:0}),
routes:[
{path:'/top/:page(\\d+)?',component:createListView('top')},
{path:'/new/:page(\\d+)?',component:createListView('new')},
{path:'/show/:page(\\d+)?',component:createListView('show')},
{path:'/ask/:page(\\d+)?',component:createListView('ask')},
{path:'/job/:page(\\d+)?',component:createListView('job')},
{path:'/item/:id(\\d+)',component:ItemView},
{path:'/user/:id',component:UserView},
{path:'/',redirect:'/top'}
]
})
}
慕姐4208626
浏览 436回答 2
2回答

德玛西亚99

constcreateListView=id=>()=>import('../views/CreateListView').then(m=>m.default(id))箭头函数(可以看看阮老师的文章了解下)其实就是constcreateListView=function(id){returnfunction(){import('../views/CreateListView').then(function(m){m.default(id)});}}

蛊毒传说

constcreateListView=id=>()=>import('../views/CreateListView').then(m=>m.default(id))这个里面可能比较让人晕头的就是这些箭头。这个是es6里面的语法--箭头函数,本质上就是function(id){//balabala}箭头前面的是参数,后面的函数内部实际处理逻辑。可以去看下es6的教程,一看就明白的,这个就是各种function了。个人理解,洗完有所帮助
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript