javascript - 类别和子类别 drodpwn 列表 vuejs 中的问题
问题描述
我有类别和子类别下拉列表,onchange 类别下拉列表获取所选类别和类别的子类别以及存储在数据库中的子类别 ID。
但问题在于在插入时选择的显示子类别选项。编辑弹出模式打开时如何调用 vuejs 方法。在 vuejs 方法中,我根据所选类别编写了子类别选择函数。
但是当编辑弹出模式打开时我无法调用此函数,此函数在 vuejs 方法中
methods: {
getcategories: function(){
let uri = 'http://localhost:8000/getAllCategory';
this.axios.get(uri).then(response => {
let $this = this;
$this.categories = response.data;
$this.id = response.data.id
$this.name = response.data.name
})
.catch(function (error) {
console.log(error);
});
},
selectSubCategory: function selectSubCategory(){
var catId = $("#categoryProduct").val();
let $this = this;
$this.axios.get('/getSubcategory', {
params: {
request: 'subcategory',
id: catId
}
})
.then(function (response) {
$this.subcategories = response.data
$this.id = response.data.id
$this.name = response.data.name
});
}
}
我调用了 selectSubCategory 函数,如下代码
$(window).on('shown.bs.modal', function() {
selectSubCategory();
});
但它给出了错误未定义的函数selectSubCategory。
有什么解决办法吗?
解决方案
Bootstrap 使用 JQuery 来触发自定义事件 hidden.bs.modal 因此它不容易被 Vue 捕获(我相信它在后台使用了本机事件)。
由于您必须在页面上使用 JQuery 才能使用 Bootstrap 的本机模式,因此只需使用 JQuery 来捕获它。假设您将 ref="vuemodal" 添加到您的 Bootstrap 模态中,您可以执行类似的操作。
在模板中 =>
<div class="modal fade" tabindex="-1" role="dialog" id="myModal" ref="vuemodal">
在脚本 => 新 Vue({
el:"#app",
data:{
},
methods:{
selectSubCategory(){
//do something
}
},
mounted(){
$(this.$refs.vuemodal).on("shown.bs.modal", this.selectSubCategory)
}
})
推荐阅读
- ios - iPhone控制面板应用程序中的蓝牙开/关状态
- android - Crashlyitics 未出现在 Firebase 中
- html - 使用Bulma在中间制作一个div填充剩余空间并滚动
- java - 如何从多线程 log4j2 缓冲区中读取
- angular - Angular 6订阅多次调用
- swift - 如何在 Scenekit macOS 应用程序中导入 obj 文件
- shell - 从 shell 将数组变量传递给 BigQuery 查询时遇到问题
- java - 检查轴对齐的边界框是否在视锥体内
- vba - 无法通过 ADODB 在访问数据库中打开连接
- node.js - node js app over cloud Foundry 失败,因为 node oracledb dep 没有在防火墙后面下载