問題:
onMounted(() => {nextTick(()=>{console.log(treeselectRef, 'treeselectRef.value');console.log(treeselectRef.value, 'treeselectRef.value');});
});
輸出:
查看綁定和定義都沒有問題,還是獲取不到
解決:使用getCurrentInstance去訪問$refs里的方法
具體操作如下:(查詢以后發現原先的ctx在線上會出現問題,需要使用proxy代替ctx)
<script setup>
import { getCurrentInstance } from 'vue';const {proxy}=getCurrentInstance()function getBaseTime() {proxy.$refs.treeselectRef.clear()}
}
</script>