一、nuxt.js 路由跳轉(zhuǎn)
1、nuxt-link標(biāo)簽跳轉(zhuǎn)
在html標(biāo)簽內(nèi)使用nuxt-link跳轉(zhuǎn),相應(yīng)于超鏈接a標(biāo)簽,使用方式如下:
<nuxt-link to="/">首頁</nuxt-link>
2、編程式導(dǎo)航-JS代碼內(nèi)部跳轉(zhuǎn)
實際項目中,很多時候都是通過在JS代碼內(nèi)部進(jìn)行導(dǎo)航的跳轉(zhuǎn),使用方式如下
this.$router.push('/xxx')
具體的簡單用法:
(1)先編寫一個按鈕,在按鈕上綁定goHome( )方法。
<button @click="goHome">回到首頁</button>
(2)在<script>模塊里加入goHome方法,并用this.$router.push(‘/’)導(dǎo)航到首頁
1. export default {
2. methods: {
3. goHome () {
4. this.$router.push('/home');
5. }
6. }
7. }
3、其他常用方法
1. // 后退一步記錄,等同于 history.back()
2. this.$router.go(-1)
3. this.$router.back(-1)
4. // 在瀏覽器記錄中前進(jìn)一步,等同于 history.forward()
5. this.$router.go(1)