Article From:https://segmentfault.com/q/1010000010964092
Question:

This is what it says in the document:

How to distribute global events in weex-html5 components or modules? Only the event is assigned on the document element:

var evt = new Event('some-type')
evt.data = { foo: 'bar' }
document.dispatchEvent(evt)

I do not work this way

  watch: {
    'speces' (val) {
        var evt = new Event('goods-update')
        evt.data = { name: 'speces', data: JSON.parse(JSON.stringify(val)) }
        document.dispatchEvent(evt)
    }
  },

Answer 0:

https://weex.apache.org/cn/re…
You can look at this part of the document
I wrote a simple example

<script>
var globalEvent = weex.requireModule('globalEvent');
globalEvent.addEventListener("goods-update", function(e) {
  console.log("get event:"+JSON.stringify(e))
});
export default {
  data: {
    target: 'World'
  },
  methods: {
    update: function(e) {
      // The trigger should not be placed here. It should be web, IOS and andorid to write a module to trigger each other./ / the code should only run on the web side; ios& Android running should be wrong.Var Val = {"X": "2"})Var EVT = new Event ('goods-update')Evt.data = {name:'speces'Data: JSON.parse (JSON.stringify (VAL))}Document.dispatchEvent (EVT)},}}< /script>

Answer 1:

A module is extended at native.
We’ve extended a notification module at native, which is acceptable on any page, weex, vue, and sends notifications for global event communication.

Similar Posts:

Leave a Reply

Your email address will not be published. Required fields are marked *