点击跳转
export default {
data() {
return {
topics:[]
}
},
created() {
this.getTopics()
},
methods: {
async getTopics() {
this.topics = await this.$http('topics')
console.log(this.topics)
},
goDetail(id) {
// // console.log(this)
// this.$router.replace({
// path:'pages/detail/detail',
// query: {
// id:id
// }
// })
// }
// this.$router.push({
// path:'/pages/detail/detail'
// })
uni.navigateTo({
url:`../detail/detail?id=${id}`
})
}
},
}
this.$router.replace({
path:'pages/detail/detail',
query: {
id:id
}
})
上面这种方法还可以写成
this.$router.replace('pages/detail/detail')
this.$router.push({
path:’/pages/detail/detail’
})
路由方法跳转不需要在main.js引入router文件夹,但必须在这段代码里写入’/pages/detail/detail’,最前面的’/‘必须要有
点击跳转的详情页面
created() {
console.log(this.$route.query)
}
onLoad(options) {
console.log(options)
}
两种方法都能得到id
路由页面
需要路由跳转时才需写路由页面