Vue2x 如何给超链接的href属性,动态拼接参数?
// 方式一:
<a v-for="item in newList" :key="item.id" :href= "'#/detail/' + item.id" :class="item.price | helperClass">
<div class="images"><img :src="'../../static/images/' +item['images']"/><i></i></div>
<div class="text"><h3>{{ item["title"] }}</h3><i>定价:{{ item["price"] }}元</i></div>
<div class="order">已订购{{ item["hasbuy"] }}万份</div>
</a>
// 方式二:
<router-link v-for="item in tuijianList" :key="item.id" :class="item.price | helperClass" :to="{name:'Detail', params: {id: item.id }}">
<div class="images"><img :src="'../../static/images/' +item['images']"/><i></i></div>
<div class="text"><h3>{{ item["title"] }}</h3><i>定价:{{ item["price"] }}元</i></div>
<div class="order">已订购{{ item["hasbuy"] }}万份</div>
</router-link>
Vue2x 获取 url 参数?
http://localhost:3333/#/index?id=001
console.log(this.$route.query.id); // 001
http://127.0.0.1:8080/#/detail/3
console.log(this.$route.params.id); // 3
网友评论