如果我理解正确,您会从您的AJAX调用中获取自定义组件的标签,并且想要构建一个Vue组件。
所以我们可以说这是你的:
Vue.component('test-component', {
template: "
I am the test component template
",methods: {
// Component logic...
}
});
现在,在您的应用程序的某个地方,你让AJAX调用:
$(document).ready(function() {
var html = '';
var url = "https://jsonplaceholder.typicode.com/posts";
$.get(url, function (data) {
var res = Vue.compile(html)
new Vue({
render: res.render,
staticRenderFns: res.staticRenderFns
}).$mount('#media_lib_app')
}.bind(this));
})
你的元件安装点:
更多关于.compile:
注意:Vue.compile()仅在完整版本中可用。
你可以在这里找到一个工作示例:
希望这可以帮助你:)