vue有兩種方法跳轉(zhuǎn)頁面
使用router-link
<router-link to="/detail">
<li class="item" v-for="item of recommendList" :key="item.id">
<img :src="item.imgUrl">
<div class="info">
<p class="info-title">{{item.title}}</p>
<p class="info-desc">{{item.desc}}</p>
<button class="btn">查看詳情</button>
</div>
</li>
</router-link>
使用$router.push 。在需要被觸發(fā)跳轉(zhuǎn)的元素上綁定跳轉(zhuǎn)事件
//跳轉(zhuǎn)到首頁
this.$router.push("/")
還有一點(diǎn)需要注意,假設(shè)我們要將li標(biāo)簽設(shè)置為router-link。此時(shí)router-link會(huì)將li標(biāo)簽渲染為a標(biāo)簽,顯然這不是我們想要的。那么可以這樣做。
//tag的意思是告訴router-link不要將此標(biāo)簽渲染為a,而是渲染為li
<router-link tag="li" to="/">