我正在尝试使用这个jquery plugin对于 vue,我读到在 vue 中包含 jquery 是不好的,但我无能为力,因为客户特别要求使用这个插件......
所以我这样做了
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);
}
}
最佳答案
找到了,我应该将绑定(bind)放在updated()上,而不是mounted()上,因为我正在动态加载数据......不需要注意它......
updated(){
this.bindScrollbar();
},
关于jquery - malihu-custom-scrollbar-plugin 具有开箱即用的 vue 动态内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47784851/