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

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e39411-65ec0.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e39411-65ec0.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?