初试vue-cli使用HBuilderx打包app的坑

2020-06-12 21:23:52易采站长站整理

function handleBack() {
var wvs=plus.webview.all();
for(var i=0;i<wvs.length;i++){
if(wvs[i].getURL() !== plus.webview.currentWebview().getURL()) {
plus.webview.close(wvs[i]);
$this.switchUrl();// 判断是后退还是回到其他页面的方法
}
}
}

动态添加的HTML节点如何绑定事件

有这个需求是因为有多语言版本,文本从后台读取。

比如

By creating your account, you agree to the Terms of Use and Privacy Policy of this site.

放在底部,点击其他地方无反应,但点击Terms of Use或者Privacy Policy则要出现条款浮层

解决办法:

后台添加语言仅修改文字,不要删除标签


<p>By creating your account, you agree to the<span data-id="0"> Terms of Use </span>and<span data-id="1"> Privacy Policy </span>of this site.</p>

这段html标签写为:


<div class="terms" @click="popup($event)" v-html="langs.REGISTER_FOOTER"></div>

事件处理:


popup (event) {
let id = event.target.getAttribute('data-id')
if(id === '0') {
console.log('Terms of Use')
}
if(id === '1') {
console.log('Privacy Policy')
}
}

只有一个点击范围的可以直接使用<span>标签,通过event.target.nodeName来判断