报错问题:
在使用uniapp运行项目的过程中,在VScode中不报错,但在浏览器调试工具时,往右滑动开始发出 错误提示
[Vue warn]: PProperty or method "scroll" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property..的报错。
--------翻译-------
PProperty或方法“滚动”未在实例上定义,但在渲染过程中被引用。通过初始化该属性,确保该属性在数据选项中或对于基于类的组件是被动的
报错原因:
属性或方法“scroll”未在实例上定义,但在渲染期间被引用。通过初始化该属性,确保该属性是被动的,无论是在数据选项中,还是对于基于类的组件。所以,由此我们就知道了,在vue的template中我们使用了scroll数据,但是在data中还并没有被定义,就被使用了,造成了这个错误。在data中定义一下这个scroll的数据就可以了。
好,现在理论知识我们已经掌握了,至于实操应该怎么操作呢?首先先看下面示范
代码为:
<template>
<view>
<view class="newbox" v-for="(item2, index2) in NewboxList " :key="index2">
<view class="posterTwo" v-if="item2.modulecode === 'Recommendnew'">
<view class="title flex">
<view class="l">
<image src="@/static/homeicon/new.png" mode=""></image>
<view class="round"></view>
{{ item2.modulename }}
</view>
<image src="@/static/more.png" class="more" mode=""></image>
</view>
<scroll-view :scroll-x="true" class="scroll-x" @scroll="scroll" scroll-with-animation="true">
<view class="scrollitem" v-for="(val, index) in item2.banner" :key="index" >
<image :src="val.thumb"></image>
</view>
</scroll-view>
</view>
</view>
</view>
</template>
报错信息:
非常好 你看到了这。 因为本人是个菜鸡也不会,所以先整理出来。后续再更新我如何解决这个问题的吧。CSDN——我的错题集~
破案啦!!!
因为我是卸载uniapp里面的组件。只要在js部分加上就好啦~
在methods里面声明一下就好了,啥也不用放。再次右滑也不会报错了~
<script>
export default {
props: {
NewboxList: {
type: Array,
default: () => {
return [];
},
},
},
methods:{
scroll(){},
}
}
</script>