如此查询网站名字是否注册,钻石网站建设,html菜单改为wordpress,在菲做平台网站例子#xff1a;
我在使用vue2开发的时候#xff0c;定义了一个方法
handler(strRef){ this.$refs[strRef].innerText hello world }#xff0c;
我在点击某个按钮的时候#xff0c;调用了方法handler#xff0c;传递了一个参数是字符串 condition#xff0c;然后方法…例子
我在使用vue2开发的时候定义了一个方法
handler(strRef){ this.$refs[strRef].innerText hello world }
我在点击某个按钮的时候调用了方法handler传递了一个参数是字符串 condition然后方法中通过 this.$refs[strRef] 后去到绑定 ref condition 的组件我在vue3中也需要通过这样的方法获取到相关组件
我们可以通过
import { getCurrentInstance } from vueconst instance: any getCurrentInstance()
获取到当前的组件实例其中 instance 就是当前组件实例
组件代码
script setup langts
import { ref, onMounted, getCurrentInstance } from vueconst instance: any getCurrentInstance()const xxx ref(hello world)
const xxxInstance ref(null)onMounted(() {console.log(instance, instance)
})
/script
templateh1 refxxxInstance{{ xxx }}/h1
/templatestyle langless scoped/style下面我们来输出一下看看 instance 下面都有什么 可以看到 instance 下面存在 refs 对象其中存在的就是绑定的各个组件实例
所以当 strRef 是字符串变量时我们可以通过 instance.refs[strRef] 的方法获取到相关的组件实例