js,我开始追赶它了,但是我被困在组件上了,谢谢你的帮助
//这是我的js
Vue.component('thatsCool', {
template: document.querySelector('#myOwnTemplate'),
data: function() {
return {
helloWorld: 'thats cool',
};
},
});
new Vue({
el: 'body',
});//这是我的html
<! DOCTYPE html>
<html>
<head>
<title>playing with Vue components</title>
</head>
<body>
<thatsCool></thatsCool>
<script id="myOwnTemplate" type="x/template">
<p v-text="helloWorld"></p>
</script>
<script src="vue.js"></script>
<script src="component.js"></script>
</body>
</html>发布于 2015-06-20 13:22:25
您的代码中有几个错误。对组件使用破折号分隔的约定,对字符串输出使用简单的手柄表示法。尝试使用以下代码:
HTML
<thats-cool></thats-cool>
<script id="myOwnTemplate" type="x-template">
<p>{{ helloWorld }}</p>
</script>JS
Vue.component('thats-cool', {
template: '#myOwnTemplate',
replace : true,
data: function() {
return {
helloWorld: 'thats cool',
};
}
});请注意,选项“替换:真”替换原来模板的el内容,而不是附加到其中。
https://stackoverflow.com/questions/30942240
复制相似问题