/**
-
读取svg文件
-
@filePath:svg文件路径
*/
readFile(filePath) {
// 创建一个新的xhr对象
let xhr = null
if (window.XMLHttpRequest) {
xhr = new XMLHttpRequest()
} else {
xhr = new ActiveXObject('Microsoft.XMLHTTP')
}
const okStatus = document.location.protocol === 'file' ? 0 : 200
xhr.open('GET', filePath, false)
xhr.overrideMimeType('image/svg+xml')
xhr.send(null)
return xhr.status === okStatus ? xhr.responseText : null
},
根据不同条件修改svg图标颜色
// 读取svg文件,修改图标颜色
var title = this.readFile(“…/images/测试.svg”);
var newSvg;
if(item.id==1){
newSvg=title.replace(/#(?:[0-9a-fA-F]{6})/g, "#FF0000")
}
if(item.id==2){
newSvg=title.replace(/#(?:[0-9a-