Search This Blog

2018/06/11

Vue.js Tips

Hide elements during loading using "v-cloak"]

v-if vs v-show
Generally speaking, v-if has higher toggle costs while v-show has higher initial render costs. So prefer v-show if you need to toggle something very often, and prefer v-if if the condition is unlikely to change at runtime.

Call vue function from outside third party js
third party js call back a function, like callbackFuc.
In outside js:
var functionName = function(response) {
    vue.$emit('vue_function_name', response)
}
window.callbackFuc = functionName ;
In vue:
....
created() {
    const _component = this;
    this.$root.$on('vue_function_name', (response) => {
        _component.function_name(response);
    }
},
methods: {
    function_name(res) {
        // to do something
    }
}

No comments :

Post a Comment