我正在尝试将此jquery 插件与 vue 一起使用,我读到将 jquery 包含在 vue 中是不好的,但我无能为力,因为客户特别要求使用此插件...
所以我做了这个
import jquery from "@/assets/js/jquery.js";
import malihu from "@/assets/js/mCustomScrollbar.js";
export default {
name: 'messages',
methods:{
bindScrollbar(){
$("#content").mCustomScrollbar({
theme:"kb",
});
}
},
mounted(){
this.bindScrollbar();
},
}
如果内容是静态的,这将正常工作。但是,如果我使用 v-for 动态加载内容,则内容是在可滚动框之外创建的……顺便说一句,我使用的是 webpack 和单个文件组件。需要帮忙
到目前为止我尝试过的解决方案:
使用这样的手表在更改时将生成的内容重新附加到容器,但它也不起作用:
watch: {
'contentValue': function(val,oldVal){
console.log($("#content")); //<-- log shows that dynamic contents are generated outside the mCSB_container...
var el = $(".contents").detach();
$(".mCSB_container").append(el);
}
}