思路:

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>

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐