[ 
https://issues.apache.org/jira/browse/WEEX-470?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16524820#comment-16524820
 ] 

Hanks Zhang commented on WEEX-470:
----------------------------------

The "weex" variables are different in each page. [1] If you register a "$xx" 
method using the "weex" variable in page B, when you back to page A, the B's 
"weex" is destroyed. It's reasonable to get an error when you calling "$xx" 
method in page A which relies on page B's weex variable.

It's important to isolate running context of each page in Weex. Do NOT use 
global variables or global methods. You can use global mixins [2] or js service 
[3].

 

[1] [http://weex-project.io/cn/references/weex-variable.html]

[2] 
[https://cn.vuejs.org/v2/guide/mixins.html#%E5%85%A8%E5%B1%80%E6%B7%B7%E5%85%A5]

[3] http://weex-project.io/cn/references/js-service.html

 

每个页面里的 "weex" 变量是不一样的而且彼此独立,如果你在 B 页面注册(覆盖)全局变量 $xx,内部实现依赖的是 B 页面里的 "weex" 
变量,退出回到 A 之后,B 的 "weex" 就废了,这时候调用 $xx 报错是正常的,因为它依赖了 B 页面的变量。

在 Weex 里比较强调环境隔离,不要注册全局变量。可以给每个页面都注册个全局的 mixin,或者用 js service。

 

 

> module lost after switch from on Activity to previous Activity
> --------------------------------------------------------------
>
>                 Key: WEEX-470
>                 URL: https://issues.apache.org/jira/browse/WEEX-470
>             Project: Weex
>          Issue Type: Bug
>          Components: Android
>    Affects Versions: 0.19
>            Reporter: 华逢义
>            Assignee: codefurture
>            Priority: Blocker
>
> Activity A started Activity B.
> B finished and back to A
> After this operation.weex.requireModule(xxx) does not work in Activity A
> the error is as follow:
> {color:#FF0000}D/jsLog: [JS Framework] Failed to requireModule("stream"), 
> instance (4) doesn't exist anymore.__ERROR{color}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to