如题:refInFor这个属性是vue原生自带的还是elementUI里面的属性?
在这里面看到的用法https://github.com/ElemeFE/el...
如题:refInFor这个属性是vue原生自带的还是elementUI里面的属性?
在这里面看到的用法https://github.com/ElemeFE/el...
这是一个 createElement
函数中的数据对象属性,当通过循环例如map
生成一个 vNode 数组时,开启 refInFor
后,在父组件中通过this.$refs.xxx
获取到的值是一个数组。
如果不开启,获取到的是最后一个元素或者子组件。
// 子组件
Vue.component("todo", {
props: ["todo"],
// createElement 可简写 h
render(h) {
console.log("todo");
console.log(this.todo);
return h("li", this.todo);
}
});
Vue.component("my-todo", {
props: ["items"],
render(h) {
console.log("my-todo");
if (this.items.length) {
const todo = this.items.map((item) => {
return h("todo", {
props: { todo: item.do },
ref: "ref-li",
refInFor: true // 使用map生成一个vNode数组,开启 refInFor: true,this.$refs.["ref-li"] 是一个数组
});
});
return h("ol", todo);
} else {
return h("p", "no todo");
}
},
mounted() {
// 在父组件中获取注册了 ref 特性的子组件的
console.log(this.$refs["ref-li"]);//数组
}
});
在数据对象中开启该选项,相当于在模板中使用 v-for
和 ref
结合生成子组件:
<todo ref="ref-li" v-for="(do,index) in todoList" :key="index">{{do}}<todo>
demo:
请采纳。思否的编辑器真是一坨xxx
10 回答11.2k 阅读
5 回答4.9k 阅读✓ 已解决
4 回答3.1k 阅读✓ 已解决
2 回答2.8k 阅读✓ 已解决
2 回答4.8k 阅读✓ 已解决
4 回答4.4k 阅读✓ 已解决
4 回答1.9k 阅读✓ 已解决