How to simulate Click events in mouted by vue

scrollLeft in vue project can only be obtained through click event. It is invalid to try through refs.xxx.click ().

Aug.22,2021

if it's just a simulated click:

var e = document.createEvent('MouseEvent');
e.initEvent('click', false, false);
this.$refs.test.$el.dispatchEvent(e);

mounted () {

    console.log(this.$refs.test.$el.offsetLeft)
}

the problem is not clear, it is best to provide online demo links. Maybe it's the loading problem. Why don't you try to set it in the setTimeout function?


just write a function to execute, why do you have to go to click?


nextTick try

Menu