- documentGetElementById找不到元素,尤其是动态加载的html部分
使用nextTick,等到vue更新完当前DOM后再查找。示例:
import {nextTick} from 'vue'; const doSomething = async(params) => { changeRefValue(html); await nextTick(); const element = document.getElementById(query); };
import {nextTick} from 'vue';
const doSomething = async(params) => {
changeRefValue(html);
await nextTick();
const element = document.getElementById(query);
};