javascript - 使用 vue js 多选动态更改选项
问题描述
嗨,我正在使用这个修改后的包装器来处理 vue js 的多项选择。我正在尝试更改此内部 vue 组件的值。这是我的代码。
<select2-multiple :options="car_options" v-model="input.classification">
<option disabled value="0">Select one</option>
</select2-multiple>
这是我的 vue 脚本,
var vm = new Vue({
el: '#el',
delimiters: ["[[", "]]"],
data: {
input: {
classification: []
},
},
created: function () {
var vm = this;
vm.car_options = [
{id: "Bubble car", text: 'Bubble car'},
{id: "diesel", text: 'Diesel'},
{id: "electric", text: 'Electric'},
{id: "electric_diesel", text: 'Electric/Diesel'},
{id: "electric_gasoline", text: 'Electric/Gasoline'},
{id: "ethanol", text: 'Ethanol'},
{id: "gasoline", text: 'Gasoline'},
{id: "hydrogene", text: 'Hydrogene'},
{id: "lpg", text: 'Liquified petroleum gas (LPG)'},
{id: "other", text: 'Other'},
];
vm.input.classification = ["Bubble car"];
}
});
我想要做的是当出现多选时应该自动选择泡泡车。如果有人可以提供帮助,那就太好了。多选工作正常,值也出现了。所以我认为问题在这里,
vm.input.classification = ["Bubble car"];
没有显示错误信息。
解决方案
似乎对我来说工作正常 - JsFiddle
vm.input.classification = [vm.car_options[0].id]
推荐阅读
- c# - 如何将图像从 App 复制到外部存储 Unity Android?
- java - H2O h2o.importFile 错误:'无法确定文件类型。对于 nfs://.../model.zip',由 water.parser.ParseDataset$H2OParse 引起
- python - 如何将来自 python 的值插入到 html 文件的正文部分?
- javascript - 在不改变文本不透明度的情况下禁用垫子扩展
- python - 如何使用 Python 和 web3.py 调用智能合约函数
- css - 如何在 CSS 中用另一个十六进制代码替换一个十六进制代码的所有实例?
- c# - 具有 SQL Server 应用程序角色的 C#:无法继续执行,因为会话处于终止状态
- java - 您如何在创建的原始窗口中的控制器之间转换
- javascript - 高性能异步请求缓存
- android - 我们如何才能让标记视图显示在可能在其下呈现的所有图表的前面?