![](https://img.haomeiwen.com/i3603263/8f7c8e1b5601f0a9.png)
1、广播的使用?
通过广播可以实现传递数据的功能。
/// page1 发送广播
const cityBroadcast = new BroadcastChannel("city_broadcast");
var data = {};
data.msg = this.province + e.citys;
data.provinceCode = this.province;
data.cityName = e.citys;
data.cityCode = e.code;
cityBroadcast.postMessage(data);
/// 在发送和接收广播的页面必须关闭广播
onDestroy() {
cityBroadcast.close();
},
/// page2...接收广播
const cityBroadcast = new BroadcastChannel("city_broadcast");
onInit() {
cityBroadcast.onmessage = function (event) {
const data = event.data;
that.sectionList[0].value = data.msg;
that.cityCode = data.cityCode;
that.provinceCode = data.provinceCode;
that.cityName = data.cityName;
}
}
/// 在发送和接收广播的页面必须关闭广播
onDestroy() {
cityBroadcast.close();
},
2、通过input组件的focus方法可以显示隐藏输入法
this.$element(this.currentInputId).focus({
focus: false
});
3、发送验证码倒计时显示按钮
sendMessageSuccess() {
this.codeColor = "#AEAEAE"
var timecount = 120;
var that = this;
that.codetext = timecount + "秒后重发";
setTimeout(function fn() {
timecount -= 1;
if (timecount == 0) {
that.codeColor = "#0677da"
that.codetext = "重新发送";
that.codeBtnDisable = false;
return false;
} else {
that.codetext = timecount + "秒后重发";
that.codeBtnDisable = true;
}
setTimeout(fn, 1000);
}, 1000);
},
4、input组件清空文本方法
<template>
<input value='{{defaultValue}}'></input>
</template>
<script>
export default {
data: {
defaultValue: ""
},
rightBtnAction(e) {
if (e.target.id == "nickname") {
this.defaultValue = new String("");
}
}
</script>
网友评论