vue 編程式js跳轉路由
阿新 • • 發佈:2018-11-17
new gone port 官方文檔 msg data 方法 節點 method
請看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跳轉路由