uniapp后端返回的html中对多个a标签自定义跳转到某个内嵌页面处理
2、拿到整个文本后,监听a标签点击事件,阻止默认事件,拿到href值,跳转自定义页面,并将值带入自定义页面。1、获取a标签href的值,渲染到自定义页面中,以web-view的形式。3、this.$nextTick()下监听a事件。
·
思路:
1、获取a标签href的值,渲染到自定义页面中,以web-view的形式。
2、拿到整个文本后,监听a标签点击事件,阻止默认事件,拿到href值,跳转自定义页面,并将值带入自定义页面。
3、this.$nextTick()下监听a事件。
当前页面:
onload(){
this.$nextTick(()=>{
this.dealTagASkip()
})
}
dealTagASkip() {
const articleEl = document.getElementById("articleEl");
const aList = articleEl.getElementsByTagName('a');
const aArray = Array.from(aList);
aArray.forEach(aEl => {
aEl.addEventListener('click', (e) => {
e.preventDefault();
uni.navigateTo({
url: `./movie?links=${aEl.href}`
})
})
})
}
movie页面展示:
<template>
<view>
<web-view :webview-styles="webviewStyles"
src="links"></web-view>
</view>
</template>
<script>
export default {
data() {
return {
links: ""
}
},
onLoad: function(option) {
this.links = option.links
},
}
</script>
更多推荐
已为社区贡献1条内容
所有评论(0)