代码中存在一个问题,即在onLoad()生命周期函数中调用了this.getActivity()方法,但是该方法并未声明在当前作用域中。因此,当调用该方法时会报错,无法读取form属性。解决该问题的方法是在方法前面添加this.来指定作用域,即将this.getActivity()修改为this.getActivity()。修改后的代码如下:

onLoad() {
    this.getActivity();
},
filters: { 
    selectName(compositionId) {
        let num = parseInt(compositionId);
        if (this.form.onceVoteAmount > 0 && this.form.onceVoteAmount == this.checkedValues.length) {
            for (var t in this.checkedValues) {
                if (t == num) {
                    return false;
                }
            }
            return true;
        } else {
            return false;
        }
    },
},
methods: {
    getActivity() {
        const url_params = Object.fromEntries(window.location.search.slice(1).split('&').map(v => v.split('=')));
        uni.request({
            url: config.baseUrl + `/activity/` + url_params.activityId,
            method: 'GET',
            success: res => {
                if (res.data.code === 200) {
                    this.form = res.data.data;
                }
            }
        });
    },
}

这样修改后的代码应该能够正常运行了

onLoad 			thisgetActivity				 filters 设置最大可选			selectNamecompositionId 				let num = parseIntcompositionId;				if thisformonceVoteAmount 0 && thisformonceVoteAmount == thischeckedValu

原文地址: https://www.cveoy.top/t/topic/imrF 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录