console
// 测试代码
const vueCode = `
new Vue({
template:\`<div>fdfdsfdsfs</div>\`,
el: document.getElementById('view_area'),
data: {
message: 'Hello Vue!'
},
methods: {
testMethod() {
console.log('正常执行');
console.log(undefinedVariable);
console.log('不会执行到这里');
}
},
mounted() {
try{
this.testMethod();
}catch(error){
console.log(error);
console.log(error.stack);
const evalMatch = error.stack.match(/eval.*<anonymous>:(\\d+):(\\d+)/);
console.log(evalMatch);
if (evalMatch !== null && evalMatch.length>0) {
console.log('报错的行号为:'+evalMatch[1])
}
}
}
})
`;
try{
eval(vueCode);
}catch(error){
console.log(error);
const evalMatch = error.stack.match(/eval.*<anonymous>:(\d+):(\d+)/);
console.log(evalMatch);
if (evalMatch !== null && evalMatch.length>0) {
console.log('报错的行号为:'+evalMatch[1])
}
}
<div id="view_area"></div>