【发布时间】:2021-11-17 10:11:23
【问题描述】:
我有一个单选按钮汽车品牌列表,我如何在选择某个品牌后从服务器获取一系列车型并将其显示在新页面上?为此需要采取哪些具体行动?非常感谢您阅读本文
<script>
export default {
name: 'Brands',
data() {
return {
brands: []
}
},
methods: {
next: function () {
this.$router.push({path: '/model'})
},
},
mounted() {
this.axios
.get('https:***')
.then(response => (this.brands = response.data.brands))
.catch(error => {
console.log(error)
})
},
}
</script>
<template>
<div class="alphabet-wrap">
<ul class="alphabet">
<li v-for="brand in brands"
:key="brand.name"
:class="brand.id"
>
<label :for="brand.id"
@change="next"
>
<input type="radio"
:id="brand.id"
name="brand"
>
<span class="text">{{ brand.name }}</span>
</label>
</li>
</ul>
</div>
</template>
【问题讨论】:
-
很大程度上取决于您的后端/api 的样子。但总的来说,我会说:选择品牌 -> 使用品牌作为查询参数重定向到新站点,然后通过 get 请求请求所有品牌模型。
标签: arrays api vue.js axios get-request