[Vue warn]: Error when evaluating expression "name.indexOf('jack') >= 0": TypeError: Cannot read property 'indexOf' of undefined
ypeError: Cannot read property 'indexOf' of undefined,从这句话中indexOf()是一个函数,但是却不能识别该属性,说明引用对象出错。
代码如下所示:
<!doctype html>
<!DOCTYPE html>
<html>
<head>
<title>dd</title>
</head>
<body>
<!-- view -->
<div id="app">
<h1 v-if="yes">yes</h1>
<h1 v-if="no">no</h1>
<h1 v-if="age>=25">Age:{{age}}</h1>
<h1 v-if="name.indexOf('jack') >= 0">Name:{{name}}</h1>
</div>
</body>
<script type="text/javascript" src="vue.js"></script>
<script type="text/javascript">
// viewModel
var vm = new Vue({
el:"#app",
data:{
yes:true,
no:false,
age:27,
naem:"jack"
}
})
</script>
</html>
总结:ypeError: Cannot read property 'indexOf' of undefined,一般情况是引用对象属性出错