在 vue.js 中渲染动态组件?
Rendering Dynamic Components in vue.js?
我正在尝试通过使用设置超时伪造 ajax 调用来呈现 vue.js 中的动态组件。它应该注册一个新组件然后在视图中设置它!我正在使用 vue.js 1.请告诉我一个解决方案,让我知道如何让它工作。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>test dynamic components</title>
</head>
<body>
<div v-component="{{currentView}}"></div>
<script src="vue-v1.js"></script>
<script>
//Create the 'default' component
Vue.component("default", {
template: '<div>This should be replaced (and will be in 2 seconds)</div>'
});
//Create the parent ViewModel
var vm = new Vue({
el: "body",
data: {
currentView: "default"
}
});
//Pretend to load the data from the server
//This would actually be $.get("/url", data, function(){...});
window.setTimeout(function () {
//Create the new component using the template we received
Vue.component("BoardFeed", {
template: '<div>Template returned from server, what I really want</div><br>And directives work too:<div v-repeat="items">{{$value}}</div>',
data: function () {
return {
items: [1, 2, 3]
};
}
});
//And then change the page to that component
vm.currentView = "BoardFeed";
}, 2000);
</script>
</body>
</html>
问题:
我正在使用 Vue.js 1,但无法插入组件的视图!我认为 v-component
even 不再被使用了
我正在尝试通过使用设置超时伪造 ajax 调用来呈现 vue.js 中的动态组件。它应该注册一个新组件然后在视图中设置它!我正在使用 vue.js 1.请告诉我一个解决方案,让我知道如何让它工作。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>test dynamic components</title>
</head>
<body>
<div v-component="{{currentView}}"></div>
<script src="vue-v1.js"></script>
<script>
//Create the 'default' component
Vue.component("default", {
template: '<div>This should be replaced (and will be in 2 seconds)</div>'
});
//Create the parent ViewModel
var vm = new Vue({
el: "body",
data: {
currentView: "default"
}
});
//Pretend to load the data from the server
//This would actually be $.get("/url", data, function(){...});
window.setTimeout(function () {
//Create the new component using the template we received
Vue.component("BoardFeed", {
template: '<div>Template returned from server, what I really want</div><br>And directives work too:<div v-repeat="items">{{$value}}</div>',
data: function () {
return {
items: [1, 2, 3]
};
}
});
//And then change the page to that component
vm.currentView = "BoardFeed";
}, 2000);
</script>
</body>
</html>
问题:
我正在使用 Vue.js 1,但无法插入组件的视图!我认为 v-component
even 不再被使用了