鍍金池/ 問答/HTML/ vuejs如何在頁面渲染完自動執(zhí)行某函數(shù)?

vuejs如何在頁面渲染完自動執(zhí)行某函數(shù)?

    ver a = new Vue({
        methods:{
            yo:function(){
                console.log('ok')
            }
        }
    })

    window.addEventListener('load',function () {
        a.yo()
    })

原本使用script標簽載入的時候我知道是這樣使用的。

但是現(xiàn)在使用vue-cli之后要怎么才能做到?

回答
編輯回答
陪妳哭

3346068135-580822cd52898
mounted里面

2018年5月24日 14:59
編輯回答
心沉

created() {
a.yo()
}

2017年12月30日 07:56
編輯回答
鹿惑

ready中的就是加載完成執(zhí)行的吧

2017年6月25日 21:07
編輯回答
不討喜

vue 生命周期函數(shù) mounted:掛載完成,即html渲染完成
mounted(){

dosomething();

}

2017年3月12日 03:30
編輯回答
青瓷
    ver a = new Vue({
        methods:{
            yo:function(){
                console.log('ok')
            }
        },
        mounted(){
            this.yo()
        }
    })
2017年10月25日 20:02
編輯回答
獨特范
export default {
    mounted: function() {
        this.yo();
    },
    methods: {
        yo:function(){
            console.log('ok')
        }
    }
}
2017年8月17日 13:33