nvue组件里
<rich-text :nodes="creatListNode(x)" :selectable="false" class="rich-text" @itemclick="test"></rich-text>
结构
creatListNode(item){
let name = `{
name: 'a',
attrs: {
class: 'name',
style:'color: #4e5c7f;font-size: 36rpx;line-height: 48rpx;',
href:'https://www.baidu.com/',
pseudoRef:'1222'
},
children: [
{
type: 'text',
text: '${item.nickname}'
}
]
},`;
let reply = item.parentId != '0'?`{
name: 'span',
attrs: {
class: 'reply'
},
children: [
{
type: 'text',
text: '回复'
}
]
},`:'';
let replyName = item.parentId != '0'?`{
name: 'a',
attrs: {
class: 'name',
style:'color: #4e5c7f;font-size: 36rpx;line-height: 48rpx;'
},
children: [
{
type: 'text',
text: '${item.replyName}'
}
]
},`:'';
let colcon = `{
name: 'span',
children: [
{
type: 'text',
text: ':'
}
]
}`
let content = ''
let loop = []
let first_arr = item.jugeContnet.split(/\#[\u4E00-\u9FA5]{1,3}\;/);
let emotions = item.jugeContnet.match(/\#[\u4E00-\u9FA5]{1,3}\;/g);
first_arr.forEach(i=>{
if(i===''){
if(emotions.length){
loop = loop.concat(eval(`[{
name: 'img',
attrs:{
class:'img',
src:'${emotionImgSrc(emotions.shift())}',
style:'width:20px;height:20px'
}
}]`))
}
}else{
loop = loop.concat(eval(`[{
name: 'span',
children: [
{
type: 'text',
text: '${i}',
style:'color: #000;font-size: 36rpx;line-height: 48rpx;'
}
]
}]`))
}
})
return eval('['+name+reply+replyName+colcon+']').concat(loop)
}
有a标签,有href,有pseudoRef,但是itemclick无法触发