bootstrap.min.css不知道为什么会出错,从中文官网下载的,用了半天之后就出错,找不到原因,从新下载了也没用 [图片] 求大佬支招,刚刚开…
顺晟科技
2022-09-16 07:12:59
191
想用vue.extend创建一个组件挂载到指定dom下,但是好像渲染不出来,是不是我使用上有什么错误呢?:testDiv原始结构:
<div id="testDiv">10000</div>
vue.extend逻辑:
let tempCom = Vue.extend({
template: '<div>123123</div>'
})
setTimeout(() => {
let t = new tempCom().$mount()
document.getElementById('testDiv').appendChild(t.$el)
}, 3000);
逻辑执行后:
我不是很认同1楼和2楼的,并且我认为extend是可以使用的。只是目前看起来是有问题的,请问控制台有警告嘛。
如果存在的话,可能是vue没编译模块导致template的无法支持加载。
应该有这句。
You are using the runtime-only build of Vue where the template compiler is not available. Either pre-compile the templates into render functions, or use the compiler-included build.
可以尝试直接使用render进行组件渲染。
const E = Vue.extend({
render: (h) => h(HelloWorldVue),
});
const e = new E({
// el: "#t"
});
const t = e.$mount();
// e.$mount().$el;
console.log(t.$el);
document.documentElement.appendChild(t.$el)
或者如果有警告就开启 vue.config.js 的 runtimeCompiler
参数
你需要 new Vue
而不是 Vue.extend
同1楼,你需要去 new
一个 vue
实例出来,然后再在实例内部去继承。
但是我看你想要做的其实并不是继承一个已有的Vue组件,所以其实你是需求是新建一个Vue实例去渲染在目标Dom内部。
02
2022-12
18
2022-10
25
2022-09
25
2022-09
25
2022-09
16
2022-09