日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > vue >内容正文

vue

vue --- vue-router

發(fā)布時間:2023/12/10 vue 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 vue --- vue-router 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

vue-router的CDN

<script src= "https://unpkg.com/vue-router@2.5.3/dist/vue-router.js"></script>// 當然還需要導入vue的cdn <script src="https://cdn.jsdelivr.net/vue/2.1.3/vue.js"></script>

使用router-link(to)添加點擊鏈接,router-view為內(nèi)容區(qū):

<div id = "app"><div class="nav"><router-link to="/learnning">學習</router-link><router-link to="/playing">玩耍</router-link></div><!-- 內(nèi)容區(qū) --><router-view></router-view> </div>

組件模板:

const learnComponent = {template:'<div>白天學習學習!!!</div>' } const playComponent = {template:'<div>晚上玩玩玩</div>' }

VueRouter關聯(lián)組件和路徑:

const router = new VueRouter({routes:[{path:'/learnning',component:learnComponent},{path:'/playing',component:playComponent}] });

router掛載到Vue上:

const app = new Vue({el:'#app',router })




完整代碼:

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="https://cdn.jsdelivr.net/vue/2.1.3/vue.js"></script> <script src="https://unpkg.com/vue-router@2.5.3/dist/vue-router.js"></script> </head><body><div id = "app"><div class="nav"><router-link to="/learnning">學習</router-link><router-link to="/playing">玩耍</router-link></div><!-- 內(nèi)容區(qū) --><router-view></router-view> </div><script>// 組件模板const learnComponent = {template:'<div>白天學習學習!!!</div>'}const playComponent = {template:'<div>晚上玩玩玩</div>'}// VueRouter關聯(lián)組件和路徑const router = new VueRouter({routes:[{path:'/learnning',component:learnComponent},{path:'/playing',component:playComponent}]});// 掛載const app = new Vue({el:'#app',router}); </script></body> </html>

參考 https://mp.weixin.qq.com/s?__biz=MzA3MDg1NzQyNA==&mid=2649654603&idx=1&sn=f13cb31acb05a4acc61b03386688a975&chksm=872c42f4b05bcbe2177881c00d4d72e1034df8b912334297c7c6a50b910b389546ef6701db71&scene=21#wechat_redirect

總結

以上是生活随笔為你收集整理的vue --- vue-router的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。