<template>
<view class="search">
<input type="text" placeholder="请输入搜索信息" v-model="searchpro" @input="select">
</view>
</template>
<script>
export default {
data() {
var s = '';
return {
array: ['中国', '美国', '巴西', '日本']
}
},
methods: {
select: function(e) {
var res = console.log(e.detail.value);
res.
console.log(res.indexOf(3132));
/ for (var i = 0; i < this.array.length; i++) {
if(this.instr(res,this.array)<0){
this.array.splice(i,1);
}
i++;
} /
},
/* instr:function (str, s) {
var dotn = str.indexOf(s);
if (dotn < 0) {
return 0;
} else {
return (dotn * 1 + 1);
}
}
*/
}
}
</script>
<style>
.search {
background-color: white;
display: flex;
align-items: center;
position: relative;
}
.search input {
padding: 5px;
font-style: normal;
border: none;
}
.search input:focus {
outline: none;
}
.search .clear_x {
position: absolute;
width: 25px;
top: 3px;
right: 25px;
border-right: 1px solid rgb(190, 187, 187);
}
.search i {
padding: 5px;
}
</style>
调用indexof方法的时候,页面报错了,
thirdScriptError
Cannot read property 'indexOf' of undefined;at pages/index/testfind page handleProxy function
TypeError: Cannot read property 'indexOf' of undefined
不知道怎么处理,刚开始学习uni-app经常遇到这种调用不到方法的问题,不知如何处理,希望给个官方的处理办法,谢谢
1 个回复
6***@qq.com (作者)
原因找到,是自己写的var res = console.log(e.detail.value);有问题,如果res被定义成undefined的话,就会报上述错误