vue注册全局方法

vue注册全局方法

  

//全局函数-main.js
import fns from './config/fns'
Object.keys(fns).forEach(key => {
    Vue.prototype[key] = fns[key]
})

//fns定义全局函数
//使用箭头函数不能拿到this
export default {
    //提示错误
    toastErrMsg: function (text) {
        this.$vux.toast.show({
            type: 'warn',
            width: '12em',
            time: 1500,
            text: text
        })
    },

    hidekeyboard() {
        window.scrollTo(0, 0);
    },

}

 

posted @ 2021-06-03 15:02  莫失莫忘_sharon  阅读(301)  评论(0)    收藏  举报