weex icon indicating copy to clipboard operation
weex copied to clipboard

Registering a Vue mixin in `src/entry.js` does not seem to work

Open tuqire opened this issue 8 years ago • 12 comments

Hi,

I initialised a weex and vue app using weex create awesome-project. In the entry.js file I am trying to register a global mixin but it does not seem to be registering. The file code is is:

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)

none of the components seem to have this.mobile as true. Works fine in the web simulator but not when I scan the QR code on my phone.

tuqire avatar Mar 02 '18 16:03 tuqire

issue was with a broken ver of weex, fixe by updating.

tuqire avatar Mar 20 '18 13:03 tuqire

me too,But I'm using the latest version

linda8167 avatar Apr 01 '18 01:04 linda8167

@linda8167 @tuqire 请问如何解决的,我这里也试了,不可以。 Vue.mixin不行。。编译完的js代码没有包含Vue.mixin()

finnome avatar Apr 11 '18 13:04 finnome

@linda8167 @pcwang0205 请问你们是怎么解决的?

starfalling avatar May 19 '18 16:05 starfalling

@starfalling 每个vue文件单独引用吧

finnome avatar May 25 '18 15:05 finnome

我们后面在native端做了这个变量注入了,也不知道用法上是对还是不对,weex的文档太简略了

starfalling avatar May 25 '18 16:05 starfalling

变量注入和mixin有啥关系?不一样吧

finnome avatar May 25 '18 16:05 finnome

目前只是注入变量,方便直接在 template 里面引用,省得每个 vue 文件都在 data 或者 computed 里面写一道。变量注入跟 mixin 当然是不一样的,不过暂时没有找到什么好的方法去用这个 mixin。weex环境下,不能在代码里面写 import vue,如果import了会导致编译出来的 JS 文件大很多,不 import 没办法调用 Vue 的函数

starfalling avatar May 25 '18 16:05 starfalling

@pcwang0205 你们还在用 weex 么?刚尝试用半个月,坑好多

starfalling avatar May 25 '18 16:05 starfalling

嗯。mixin这样用 11111111111

finnome avatar May 25 '18 16:05 finnome

那还是得每个文件都要写一道了,不过这个比每个vue文件都写一遍要强了,没有文档全靠摸索,可以加个QQ交流么?

starfalling avatar May 25 '18 16:05 starfalling

@starfalling qq: 823312251

finnome avatar May 25 '18 16:05 finnome