关于 vue.js:在 weex 中初始化一个全局 mixin

initialising a global mixin in weex

我使用 weex create awesome-project 初始化了一个 weex 和 vue 应用程序。在 entry.js 文件中,我试图注册一个全局 mixin,但它似乎没有注册。代码是:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import weex from 'weex-vue-render'
import Vue from 'vue'

Vue.mixin({
  computed: {
    device () {
      return 'mobile'
    },
    browser () {
      return this.device === 'browser'
    },
    mobile () {
      return this.device === 'mobile'
    }
  }
})

weex.init(Vue)

没有一个组件有 this.mobile 为真。在网络模拟器中工作正常,但当我在手机上扫描二维码时就不行了。


仅供参考。好像我刚刚有一个损坏的 Weex 版本!如果你发现自己遇到了这个问题,只需更新 Weex,启动一个新项目并将所有代码移过来。对我来说就像一个魅力。