当前位置:首页 > 千层云服务器 > 正文

vue中如何访问路由

在vue中访问路由的方法:1.新建vue.js项目;2.使用import方法添加路由;3.使用mode:'history'去除vue访问页面时的#/;4.浏览器输入localhost:8080/myVue访问路由;

vue中如何访问路由

具体步骤如下:

1.首先,在vue-cli中创建一个vue.js项目;

vue create project-name

2.vue.js项目创建好后,在项目中使用import方法添加一个路由;

import myTestVue from '@/components/myTestVue'

3.路由添加好后,使用mode:'history'去除vue访问页面时的#/;

Vue.use(Router)

export default new Router({

mode:'history',

routes:[

{

path: '/',

name: 'HelloWorld',

component:HelloWorld

},

{

path: '/myVue',

name: 'myTestVue',

component:myTestVue

}

]

})

4.最后,运行项目,在浏览器中输入localhost:8080/myVue即可访问路由;

如果您对该产品感兴趣,请填写办理(客服微信:xiaoxiongyidong)

为您推荐:

发表评论

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

在线客服