仅支持使用eslint格式化后的vue文件
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<textarea cols="200" rows="20" id="content"></textarea>
<button id='zhuanhuan'>查找</button>
</body>
<script>
var content=''
document.getElementById('zhuanhuan').addEventListener('click',function(){
content = document.getElementById('content').value
let obj=content.substring(content.indexOf('export default')+15,content.indexOf('</'+'script>'))
obj = (obj.substring(1,obj.search("\n },")))
content=content.replace(obj,"")
//删除所有的注释
obj=(obj.replace(/\/\/.*?\n/g,''))
obj=obj.replace('data () {\n return ','')
obj=(obj.replace(/.*?\,/,''))
obj=(obj.replace(/ |\n/,''))
obj=obj.substring(0,obj.length-1)
obj=obj.substring(4,obj.length-1)
obj=(obj.replace('\n ',''))
obj=(obj.replace(/\n\s{8,}/g,''))
obj=obj.split(",\n")
for(let ind = 0;ind<obj.length;ind++){
let serachContent = obj[ind].split(":")[0].replace(/\s/g,'')
let reg=new RegExp("(this\\.|\\{{|\\()"+serachContent + '(\\.|\\s|}}|\\))', 'g')
let regResult = content.match(reg)
if (!regResult) {
//打印未使用的data
console.log(serachContent)
}
}
})
</script>
</html>