我寫個(gè)組件,想實(shí)現(xiàn)這樣的效果:<info-list @on_data="fetch_data">
<info-item title_field="xxx" link="/xxx/{{ item.id }}"/>
</info-list>然后List的模板大概這樣:<script type="x/template" id="info-list">
... <div v-for="item in items">
<slot></slot>
</div>
...</script>Item的模板大概這樣:<script type="x/template" id="info-item">
..... <a href="{{ link }}">{{ item[title_field] }}</a>
......</script>主要是問題是,slot里的組件,如何訪問外層的狀態(tài)。我看到stackoverflow也有人問類似的問題:http://stackoverflow.com/questions/37248411/how-to-access-item-in-slot-inside-v-for-vue-js還有:http://forum.vuejs.org/topic/366/slot-as-an-item-row-template/6
vue.js v-for里套slot,如何訪問v-for當(dāng)前值?
DIEA
2018-08-07 16:10:31