uniapp中 使用了组件 但是右滑在渲染页面一直报错

报错问题:
在使用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>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值