最近搜索

vue 接受参数

浏览:500
管理员 2021-03-16 09:24




第一种是 result风格


pathnamecomponentView


http://localhost:8080/#/view/1


输出代码

let url = getServerUrl('/api/vue/food/findById');
axios.get(url, {params: {id: this.$route.params.id}}).then(response => {
  console.log(response.data)
  this.foodObj = response.data;
}).catch(error => {
  alert(error);
})


需要 路由配置

},{
  path: '/type/:id',
  name: 'Type',
  component: Type
}



第二种 query风格,案例1

console.log(this.q);
this.$router.replace('/search/result?q='+this.q);


mounted() {
  console.log(this.$route.query.q);
},


不需要路由配置

,{
  path: '/search/result',
  name: 'SearchResult',
  component: SearchResult
}


第二种 query风格 ,案例2

 image.png




联系站长

站长微信:xiaomao0055

站长QQ:14496453