如何为渲染函数添加引用?
我有一个custom_modal用于在以下位置显示自定义模式的实用程序util.js:
util.custom_modal = function (context ) {
context.$Modal.info({
render: (h) => {
return h('div', {
},[
h('div', {props: {ref:"abc"}, attrs: {} }, 'ABC')
])
}
})
Run Code Online (Sandbox Code Playgroud)
当我在组件中使用模态 util 时,this.$refs没有引用abc。
util.custom_modal(this)
Run Code Online (Sandbox Code Playgroud)
console在我输入的浏览器中this.$refs,没有参考abc。
在渲染函数中,我还将引用放在属性中:
h('div', {props: {}, attrs: {ref:"abc"} }, 'ABC')
Run Code Online (Sandbox Code Playgroud)
它仍然不起作用。
您ref直接使用(不作为属性):
h('div', {props: {}, ref:"abc"}, 'ABC')
Run Code Online (Sandbox Code Playgroud)
另一个例子,一个
<input type="text" ref="foobar">
Run Code Online (Sandbox Code Playgroud)
将会:
h('input',{ref:"foobar",attrs:{"type":"text"}})
Run Code Online (Sandbox Code Playgroud)
演示:
h('div', {props: {}, ref:"abc"}, 'ABC')
Run Code Online (Sandbox Code Playgroud)
<input type="text" ref="foobar">
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2753 次 |
| 最近记录: |