我是Vue的新手(版本2.5),在我的项目中,我安装了v-select插件,查看文档时有些地方让我感到困惑。
以下是我的代码:
<template>
<div class="wrapper">
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label for="name">Category</label>
<v-select label="category_desc" options="category"></v-select>
</div>
</div>
</div>
<button type="button" variant="primary" class="px-4" @click.prevent="next()">next</button>
</div>
</template>
<script>
export default {
name: 'Addproduct',
data () {
return {
category:[]
}
},
mounted() {
this.$http.get('http://localhost:3000/api/categories') .then(function (response) {
console.log(response.data);
this.category=response.data
})
.catch(function (error) {
console.log("error.response");
});
},
方法:{ next(){ // console.log('value of v-selection not option' ) eg id 1 has 'country' so i want id 1 in method next() i.e in console.log } } 现在我的问题是如何将axios响应的成功值传递给v-select选项,第二个问题是我如何获取v-select的选定值,例如:当用户单击下一个按钮时,我如何知道v-select中选择了哪个值
.bind(this)
将this
绑定到作用域中,这样会更加简洁。请参考我上面的编辑。如果我的回答有帮助,请考虑将其标记为被接受的答案。 - undefined