uniapp开发父组件调用子组件方法报错“this.$refs.xxxx“,检查是否组件用了v-if,如果是改为v-show试试

news/2024/7/10 0:51:21 标签: uni-app, vue

 

在父类组件中

<template>
    <view>
        <MemberLogged ref="isLogged" @toLogIn="gotoLogging" v-if="proposItem.active===1"></MemberLogged>
    </view>
</template>

 

 

子类组件中有

methods: {
      
            showLogged: function(data) {
                console.log("我被父组件调用了")
                this.propsItem.isLogged=data;
            
            },

}

 

当父类组件的方法中执行this.$refs.isLogged.showLogged(this.proposItem.isLogged);报错this.$refs.xxxx

后来网上找了很久父类调用字类的方法,都这么写的,最后发现一篇比较好的博文,说如果组件中用了v-if也会引起这个问题,后我修改父类组件如下

<template>
    <view>
        <MemberLogged ref="isLogged" @toLogIn="gotoLogging" v-show="proposItem.active===1"></MemberLogged>
    </view>
</template>

 

问题得到解决

开发父组件调用子组件方法报错"this.$refs.xxxx",检查是否组件用了v-if,如果是改为v-show试试


http://www.niftyadmin.cn/n/1464348.html

相关文章

完美解决序微信小程序不能用本地ip调试的问题,不在以下 request 合法域名列表中,请参考文档:https://d

微信小程序不能用本地ip调试的问题&#xff0c;错误如下 不在以下 request 合法域名列表中&#xff0c;请参考文档&#xff1a;https://developers.weixin.qq.com/miniprogram/dev/framework/ability/network.html i 通过链接过去看到 只要通过对微信开发者工具进行以下设置即…

jquery添加click事件,jq动态添加click事件多种方式分享

目录&#xff1a; 添加方式 实例演示 添加方式 $("#ImId1").click(function(){}); $("#ImId2").bind("click",function(){}) $("#ImId3").on("click",function(){}) $("body").delegate("#xxx","c…

内网穿透,解决vue项目中的“Invalid Host header”

在webpack.dev.config.js&#xff0c;加入devServer: { disableHostCheck: true }&#xff0c;具体如下图 结果就能通过内网穿透了&#xff0c;访问结果

配置spring boot jpa控制台打印sql日志

在application.properties中加入以下两行 spring.jpa.properties.hibernate.format_sqltrue spring.jpa.properties.hibernate.show_sqltrue运行起来看到这样的结果

看完这篇能解决一些关于element ui table控件的使用常见问题,如table中自定义a标签,列中加入复选框或者序号列,时间控件的格式问题等

在script中加入 var app new Vue({el: #app,data: function () {return { itemList:[],}}, created: function() {//初始化你的table数据this.itemList你的list数据 }, methods: { submitForm: function (formName) {// }, resetForm: function (formName) {this.$refs[form…

java 模拟表单post提交

Java /*** 模拟提交表单* param url* param sb*/ public static String postByFormData(String url,StringBuffer sb){String responseMessage "";StringBuffer response new StringBuffer();HttpURLConnection httpConnection null;OutputStreamWriter out nul…

记录一次linux 安装jdk1.8

准备linux 版本的jdk ,自行到百度找到并下载&#xff0c;这里只介绍预备好压缩包的安装方式 传到服务器你管理软件的文件夹, 我的是/usr/local/soft 创建一个用来安装java的文件夹 mkdir /usr/local/java 从刚准备好的tar包的文件夹中解压到/usr/local/java中 tar zxvf /u…

linux 安装nginx,nginx error: the HTTP rewrite module requires the PCRE library;the HTTP gzip module re

问题&#xff1a;nginx error: the HTTP rewrite module requires the PCRE library. 执行&#xff1a;yum -y install pcre-devel 问题&#xff1a;the HTTP gzip module requires the zlib library. 执行&#xff1a;yum install -y zlib-devel