1.在小黑框里面输入npm install vue-router -S 安装路由
2.在src内新建router目录 添加index.js作为总路由
在 index.js里面写3.
// 引入依赖
import Vue from 'vue'
import Router from 'vue-router'
//引入文件路径
import HelloWorld from '../components/TakeOut.vue'
Vue.use(Router)
export default new Router({
routes: [
{
path: '/',
name: 'HelloWorld',
component: HelloWorld
},
]
})
3.在main.js里面的写
import router from './router'
new Vue({})
new Vue({
el: '#app',
router:router, //写这一条
components: { App },
template: '<App/>'
})
这篇博客介绍了如何在Vue.js项目中安装和配置路由。首先,通过npm安装vue-router,然后在src目录下创建router目录并编写index.js文件,导入Vue和Vue Router,并设置基本路由。接着,在main.js中引入router实例并注入到Vue实例中,确保路由在应用中生效。
2797

被折叠的 条评论
为什么被折叠?



