html結構是這樣的:
<p class="main" id="main">
<p class="top"></p>
<p class="body-box">
<p class="left" id="left">
<p class="menu-btn-box">
<span class="menu-btn" id="menu_btn"></span>
</p>
<tools-list></tools-list>
</p>
<p class="middle">
<router-view></router-view>
</p>
</p>
</p>
js程式碼是這樣的:
var tools_list_arr = [
{
title: '在线云盘',
thisUrl: '/yunpan'
},
{
title: '作业系统',
thisUrl: '/zuoye',
children: [
{
title: '作业布置',
thisUrl: '/buzhi'
},
{
title: '作业评估',
thisUrl: '/pingu'
},
{
title: '作业查重',
thisUrl: '/chachong'
},
]
}
];
Vue.component('tools-list',{
template:'<ul class="tools-list" id="tools_list">\
<li v-for="item in items" class="tools-li">\
<router-link to="item.thisUrl">\
{{item.title}}\
</router-link>\
<ul class="tools-li-list">\
<li v-for="childItem in item.children" class="tools-li-list-li">\
<router-link to="childItem.thisUrl">\
{{childItem.title}}\
</router-link>\
</li>\
</ul>\
</li>\
</ul>',
data: function(){
return {
items: tools_list_arr
};
}
})
new Vue({
el: '#left'
})
//路由
const Home = {
template: '<p>Home</p>'
}
const First = {
template: '<p>First</p>'
}
const routes = [
{path: '' , component: Home },
{path: '/qiandao' , component: First },
]
const router = new VueRouter({
routes : routes
})
const main = new Vue({
el: '#main',
router,
render: h => h(toolsList) //vue官方文档没这句,但网上查好像得添加这句,但我不知道h()的括号里写什么
}).$mount('#main')
報錯如下
render
你已經加入了
el
选项了就不用再添加render
了