<rich-img :nodes="nodes" @click="clickImages(nodes)"></rich-img>
/**
* @params images ==> '<img src="https://example.com/image1.jpg" alt="Image 1"><img src="https://example.com/image2.jpg" alt="Image 2">';
*/
clickImages(images = '') {
// 定义你想要提取的img标签数量
let imageMatches = images.match(/<img/g);
// 获取img的个数
let n = imageMatches ? imageMatches.length : 0;
// 使用正则表达式提取src属性值
let regex = /<img.*?src=[;"](.*?)['"]/g;
let matches = [];
let match = [];
while(n > 0 && (match = regex.exec(images))) {
matches.push(match[1]);
n--;
}
console.log(matches); // 输出: ["https://example.com/image1.jpg", "https://example.com/image2.jpg"]
uni.previewImage({
urls: matches, // 图片地址,urls是数组格式
current: '', // 选填:图片默认打开第一张;第一次打开的图片url地址
success: function(res) {
},
fail: function(res) {
},
complete: function(res) {
},
})
},
uniapp点击图片放大预览
于 2023-09-15 10:01:07 首次发布