如题,我是新手,目前课设只需要一丢vue的知识,课设后再学多一点vue。
我设置了路由,入门的那种,正如vue文档里也一样,它的实例是
const NotFound = { template: '<p>Page not found</p>' }
const Home = { template: '<p>home page</p>' }
const About = { template: '<p>about page</p>' }
const routes = { '/': Home, '/about': About }
new Vue({ el: '#app',
data: { currentRoute: window.location.pathname },
computed: { ViewComponent () {
return routes\[this.currentRoute\] || NotFound } },
render (h) { return h(this.ViewComponent) } })
如果按上面来,那template就要直接写在里面,我的template都是很多内容的,而且直接塞进去会报错,就是不知道要如何放在外面然后可以导进来用,求解!QAQ
首先要导入
vue
、vue-router
的包然后如果template太大的话可以拆成单文件组件,或者使用模板字符串。
另外官方文档其实很详细,可以多看看。