码迷,mamicode.com
首页 > Web开发 > 详细

vue 编程式js跳转路由

时间:2018-11-17 17:50:17      阅读:222      评论:0      收藏:0      [点我收藏+]

标签:efault   home   def   push   新闻   port   outer   div   col   

请看goNews()方法

 1 <template>
 2     <!-- 所有的内容要被根节点包含起来 -->
 3     <div id="home">    
 4        我是首页组件
 5 
 6 
 7         <button @click="goNews()">通过js跳转到新闻页面</button>
 8        
 9     </div>
10 </template>
11 
12 
13 <script>
14     export default{
15         data(){
16             return {               
17                msg:‘我是一个home组件‘
18              
19             }
20         },
21         methods:{
22 
23             goNews(){
24 
25 
26                 // 注意:官方文档写错了
27 
28 
29                 //第一种跳转方式
30 
31                 // this.$router.push({ path: ‘news‘ })
32 
33 
34                 // this.$router.push({ path: ‘/content/495‘ });
35 
36 
37 
38 
39 
40 
41 
42                 //另一种跳转方式
43 
44                     //   { path: ‘/news‘, component: News,name:‘news‘ },
45 
46 
47                     // router.push({ name: ‘news‘, params: { userId: 123 }})
48 
49 
50                     this.$router.push({ name: ‘news‘})
51 
52 
53                 
54 
55             }
56         }
57     }
58 
59 </script>
60 
61 <style lang="scss" scoped>
62     
63 </style>

 

vue 编程式js跳转路由

标签:efault   home   def   push   新闻   port   outer   div   col   

原文地址:https://www.cnblogs.com/sulanlan/p/9974643.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!