鍍金池/ 問答/HTML/ 向組件中傳入prop為什么出現(xiàn)在標(biāo)簽屬性部分

向組件中傳入prop為什么出現(xiàn)在標(biāo)簽屬性部分

  1. `
Vue.component('todoItem', {
            props:['todo'],
            template: '<span>{{todo}}</span>'
        });
new Vue({
    el:"#example5",
    data:{
        todo:{
            text:'hello'
        }
    }
});

`

  <div id="example5">
    <todo-item v-bind="todo"></todo-item>
  </div>

最后效果是

<div id="example5"><span text="hello"></span></div>

我覺得奇怪的是todo對(duì)象為什么會(huì)以屬性:屬性值的形式出現(xiàn)在標(biāo)簽<span>里。
本來template我是這么寫的,template: '<span>{{todo.text}}</span>'
但是報(bào)錯(cuò),這個(gè)text始終讀不到。

請(qǐng)各位幫忙看看

回答
編輯回答
尐懶貓

v-bind="todo"寫錯(cuò)了
應(yīng)是:todo="todo"
然后 template 你就可以寫成:
'<span>{{todo.text}}</span>'

2017年3月2日 23:42
編輯回答
爛人
// todo對(duì)象傳遞,應(yīng)該這樣
<todo-item v-bind:todo="todo"></todo-item>
// todo.text的值傳遞,應(yīng)該這樣
<todo-item v-bind:todo="todo.text"></todo-item>
2017年5月22日 19:18