Javascript 如何为渲染函数添加ref?
如何为渲染函数添加ref 我有一个Javascript 如何为渲染函数添加ref?,javascript,vue.js,Javascript,Vue.js,如何为渲染函数添加ref 我有一个custom_modalutil,用于在util.js中显示自定义模态: util.custom_modal = function (context ) { context.$Modal.info({ render: (h) => { return h('div', { },[ h('div', {props: {ref:"abc"}, attrs: {} }, 'ABC') ])
custom_modal
util,用于在util.js
中显示自定义模态:
util.custom_modal = function (context ) {
context.$Modal.info({
render: (h) => {
return h('div', {
},[
h('div', {props: {ref:"abc"}, attrs: {} }, 'ABC')
])
}
})
当我在组件中使用模态util时,this.$refs
没有abc
ref
util.custom_modal(this)
在浏览器的控制台中
I键入this.$refs
,没有abc
ref
util.custom_modal(this)
在render函数中,我还将ref放入属性:
h('div', {props: {}, attrs: {ref:"abc"} }, 'ABC')
它仍然不起作用。您直接使用
ref
(不作为属性):
另一个例子,a
<input type="text" ref="foobar">
演示:
newvue({
el:“#应用程序”,
数据:{},
渲染(h){
返回h('input',{ref:'foobar',attrs:{“type”:“text”})
},
安装的(){
log('My foobar input:',this.$refs.foobar);
}
})
h('input',{ref:"foobar",attrs:{"type":"text"}})