• 0
  • 0

Uniapp 定义全局方法和变量

2019-06-28 1042 0 admin 所属分类:Hbuilder

在Uniapp中采用Vue开发,支持像继承一样的东西可以全局定义一套公用的方法和变量供某个page对象使用 

需要在main.js文件中定义如下结构

Vue.mixin({
    //你的变量
    data() {
        return data
    },
    methods: {
        //你的方法列表
        locationmap() {
            if (this.g.openLocation == true) {
                this.g.openLocation = false;
                uni.openLocation({
                    longitude: this.g.open_longitude,
                    latitude: this.g.open_latitude,
                    name: this.g.open_name,
                    address: this.g.open_address,
                })
            }
        }
    }
});


返回顶部