<template>
<view>
<rich-text :nodes="change(string)"></rich-text>
</view>
</template>
<script>
import server from '@/api/index.js'
export default {
data() {
return {
string: '',
};
},
onLoad() {
this.getysxy();
},
methods: {
getysxy(){
server.getysxy().then(res =>{
console.log('隐私协议',res)
this.string = res;
if(res.length > 0){
this.string = res.value;
}
})
},
change(data){
if(data){
let html = data.replace(/<img([\s\w"-=\/\.:;]+)((?:(height="[^"]+")))/ig, '<img$1')
.replace(/<img([\s\w"-=\/\.:;]+)((?:(width="[^"]+")))/ig, '<img$1')
.replace(/<img([\s\w"-=\/\.:;]+)((?:(style="[^"]+")))/ig, '<img$1')
.replace(/<img([\s\w"-=\/\.:;]+)((?:(alt="[^"]+")))/ig, '<img$1')
.replace(/<img([\s\w"-=\/\.:;]+)/ig, '<img style="width: 100%;" $1');
return html
}
}
}
}
</script>
<style lang="scss">
</style>
uniapp中使用富文本进行展示
最新推荐文章于 2024-07-04 10:59:43 发布