weex - BroadcastChannel在APP中使用无效?
本文介绍了weex - BroadcastChannel在APP中使用无效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
按照官方文档,BroadcastChannel是在JS Framework API中,我在APP里两个we页面中写了发送和接受代码,但是一点反应也没有。是不是APP中BroadcastChannel是不起作用的?
index.we
<template>
<div class="app">
<text onclick="click" style="width:300px;height:200px;">show test page</text>
</div>
</template>
<style>
</style>
<script>
var navigator = weex.requireModule('navigator')
module.exports = {
data:{
event:""
},
created:function(){
var self=this;
const Stack = new BroadcastChannel('Avengers')
Stack.onmessage = function (event) {
self.event=event.data;
}
},
methods:{
click:function(){
navigator.push({
url:"http://192.168.0.120:8080/dist/views/test.js",
animated: "true"
},function(e){
});
}
}
}
</script>
views/test.we
<template>
<div class="app">
<text>this is test page</text>
<text onclick="click" style="width:300px;height:200px;">click this text</text>
</div>
</template>
<style>
</style>
<script>
module.exports = {
data:{
},
created:function(){
},
methods:{
click:function(){
const Hulk = new BroadcastChannel('Avengers')
Hulk.postMessage("I click this text")
}
}
}
</script>
解决方案
注意 SDK 版本,得 0.9.5 或以上才支持 BroadcastChannel ,明天就会发 0.10.0 。
获取 WeexSDK 版本: http://dotwe.org/weex/8c2fb81...
这篇关于weex - BroadcastChannel在APP中使用无效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文