如何修复V-Model的选择选项Onchange返回先前选择或成为静态值,而不是使用vue.js的当前值?
当我访问消息页面并选择设备时,我有问题,V-Model选择值将会更改。但是,如果我访问“设备”页面并联系页面,则V-Model所选值不会更改或设置为我选择的最后一个时间值。
这是我在devicecontroller
中的功能:以获取设备:
public function devices()
{
try {
$devices = Device::orderby('id', 'asc')->get();
return response()->json($devices);
} catch (\Throwable $th) {
return response()->json(['message' => $th->getMessage()]);
}
}
这是从devicecontroller
中获取decection
数据的方法的功能:
getDevices() {
axios.get(`/api/devices`)
.then(response => {
this.devices = response.data;
});
},
这是我的选择选项代码:
<select class="form-select form-select-lg mb-3" v-model="choosed" @change="onChange()">
<option :value="null">Choose Device to Send SMS</option>
<option v-for="item in devices" :key="item.id" :value="item.id" >{{ item.device_name }}
</option>
</select>
这是我所选的V-Model和设备JSON,该设备设备该项目。ID来自数据:
export default {
data() {
return {
devices: {},
choosed: null,
}
},
}
这是我的onChange
in thate in方法:
onChange: function(){
this.choosed = this.item.id;
},
I have a problem when I visit the message page and I select a device, the v-model selected value will change. But if I visit the device page and contact page the v-model selected value will not change or become set to the last time value that I selected.
Here is my function in DeviceController
to fetch devices:
public function devices()
{
try {
$devices = Device::orderby('id', 'asc')->get();
return response()->json($devices);
} catch (\Throwable $th) {
return response()->json(['message' => $th->getMessage()]);
}
}
Here is the function from method to get devices{}
data from DeviceController
:
getDevices() {
axios.get(`/api/devices`)
.then(response => {
this.devices = response.data;
});
},
Here is my select option code:
<select class="form-select form-select-lg mb-3" v-model="choosed" @change="onChange()">
<option :value="null">Choose Device to Send SMS</option>
<option v-for="item in devices" :key="item.id" :value="item.id" >{{ item.device_name }}
</option>
</select>
Here is my selected v-model and devices JSON which devices that item.id came from in data:
export default {
data() {
return {
devices: {},
choosed: null,
}
},
}
Here is my onChange
function in method:
onChange: function(){
this.choosed = this.item.id;
},
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
删除函数
onChange
- 这是显而易见的。Remove the function
onChange
- it is plain wrong.