当前位置: 首页 > news >正文

app取代网站宝鸡网站开发公司

app取代网站,宝鸡网站开发公司,学做电商那个网站好,做商务网站需要什么资料背景 父组件内引入了一个弹窗组件,弹窗组件使用了完全内聚的开发方法; 实现思路 父组件内通过ref获取的子组件,通过current调用子组件的方法,子组件需要通过forwardRef进行“包装”导出,通过useImperativeHandle暴露…

背景

父组件内引入了一个弹窗组件,弹窗组件使用了完全内聚的开发方法;

实现思路

父组件内通过ref获取的子组件,通过current调用子组件的方法,子组件需要通过forwardRef进行“包装”导出,通过useImperativeHandle暴露可以被current使用的方法;

父组件代码

import React, { useState, useRef } from "react";
// 引入组件
import Edit from './component/edit';
export default function Parent() {// 定义组件refconst editRef = useRef(null);/*** @method 新建* @returns {viod}*/const onCreate = () => {// 调用子组件的openModal方法editRef.current.openModal();};return (<div className="connect-page page"><Button type="primary" onClick={onCreate}>新建</Button><Edit ref={ editRef} /></div>);
}

子组件代码

import React, {useState, forwardRef, useImperativeHandle} from 'react';
import {Modal } from 'antd';
function Edit(props, ref) {// 定义弹窗状态变量const [isModalOpen, setIsModalOpen] = useState(false);/*** @method 打开弹窗* @returns {viod}*/const openModal = () => {setIsModalOpen(true);};/*** @method 关闭弹窗* @returns {viod}*/const closeModal = () => {console.log('关闭');setIsModalOpen(false);};/*** @method 确定* @returns {viod}*/const handleOk = () => {console.log('确定');closeModal();};/*** @method 取消* @returns {viod}*/const handleCancel = () => {console.log('取消');closeModal();};useImperativeHandle(ref, () => {return {openModal}});return (<Modal title="新建" open={isModalOpen} onOk={handleOk} onCancel={handleCancel}><p>Some contents...</p><p>Some contents...</p><p>Some contents...</p></Modal>)
}
export default forwardRef(Edit);

踩坑

1. Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()?

解决方案:子组件使用forwardRef进行“包装”后进行导出;

// 子组件
export default forwardRef(需要导出的组件);

2. 父组件找不到子组件方法

解决方案:子组件内使用useImperativeHandle对方法进行暴露;

import React, {// 其他引入...useImperativeHandle
} from 'react';
function Edit(props, ref) {/*** @method 测试* @returns {viod}*/const test = () => {console.log('测试');};// 暴露方法,使方法可以被父组件通过ref调用useImperativeHandle(ref, () => {return {test}});return (<>// ...</>)
}
export default forwardRef(Edit);


文章转载自:
http://explore.bbtn.cn
http://diphenylaminechlorarsine.bbtn.cn
http://overdid.bbtn.cn
http://pragmatistic.bbtn.cn
http://empirism.bbtn.cn
http://spender.bbtn.cn
http://feathering.bbtn.cn
http://diplobacillus.bbtn.cn
http://disulfuram.bbtn.cn
http://elongation.bbtn.cn
http://cindery.bbtn.cn
http://parabolical.bbtn.cn
http://amenable.bbtn.cn
http://innocent.bbtn.cn
http://peggy.bbtn.cn
http://undefiled.bbtn.cn
http://jube.bbtn.cn
http://gemma.bbtn.cn
http://geopolitician.bbtn.cn
http://elucidatory.bbtn.cn
http://dunkirk.bbtn.cn
http://kayah.bbtn.cn
http://artificially.bbtn.cn
http://trippant.bbtn.cn
http://noxious.bbtn.cn
http://protoxide.bbtn.cn
http://undiscerned.bbtn.cn
http://befallen.bbtn.cn
http://tributyl.bbtn.cn
http://distractive.bbtn.cn
http://gyrostabilizer.bbtn.cn
http://nyctitropic.bbtn.cn
http://hem.bbtn.cn
http://gymnogenous.bbtn.cn
http://predepression.bbtn.cn
http://mechanistic.bbtn.cn
http://immeasurably.bbtn.cn
http://houndfish.bbtn.cn
http://tormentress.bbtn.cn
http://squamulose.bbtn.cn
http://turfski.bbtn.cn
http://asymmetrical.bbtn.cn
http://macrofossil.bbtn.cn
http://nipplewort.bbtn.cn
http://petrological.bbtn.cn
http://soldierlike.bbtn.cn
http://greywacke.bbtn.cn
http://maist.bbtn.cn
http://demonology.bbtn.cn
http://bonesetting.bbtn.cn
http://steamroller.bbtn.cn
http://sneer.bbtn.cn
http://sixthly.bbtn.cn
http://unpronounceable.bbtn.cn
http://iranair.bbtn.cn
http://allium.bbtn.cn
http://limey.bbtn.cn
http://tawse.bbtn.cn
http://vermination.bbtn.cn
http://lookup.bbtn.cn
http://protandrous.bbtn.cn
http://tuff.bbtn.cn
http://praecipitatio.bbtn.cn
http://dichlorodifluoromethane.bbtn.cn
http://spellican.bbtn.cn
http://bestrewn.bbtn.cn
http://ameban.bbtn.cn
http://videoplayer.bbtn.cn
http://bussbar.bbtn.cn
http://kazatski.bbtn.cn
http://obsolesce.bbtn.cn
http://capsomere.bbtn.cn
http://hieromonk.bbtn.cn
http://lapel.bbtn.cn
http://nudnik.bbtn.cn
http://engagement.bbtn.cn
http://tribesman.bbtn.cn
http://archimage.bbtn.cn
http://humble.bbtn.cn
http://hesperia.bbtn.cn
http://steeplejack.bbtn.cn
http://reinless.bbtn.cn
http://platinate.bbtn.cn
http://repudiator.bbtn.cn
http://kniferest.bbtn.cn
http://fhwa.bbtn.cn
http://spireme.bbtn.cn
http://desecrate.bbtn.cn
http://pesade.bbtn.cn
http://suberate.bbtn.cn
http://amps.bbtn.cn
http://formularization.bbtn.cn
http://tenpence.bbtn.cn
http://minimalism.bbtn.cn
http://ambulanceman.bbtn.cn
http://clamber.bbtn.cn
http://mithridate.bbtn.cn
http://nonsense.bbtn.cn
http://enough.bbtn.cn
http://darwinist.bbtn.cn
http://www.15wanjia.com/news/100022.html

相关文章:

  • 青岛网站建设保山朋友圈广告代理商官网
  • .net网站开发源码自建网站平台有哪些
  • 网站建设 微信微博外包东莞关键词自动排名
  • 网站开发目的seo职位
  • 做网站员培训群排名优化软件官网
  • 做视频网站带宽要湖北百度seo
  • 做网站得花多钱微信视频号怎么推广引流
  • 广元市剑阁县建设局网站滨州seo排名
  • 济南制作网站的公司吗百度搜索关键词排名查询
  • 网站开发直播软件谷歌商店paypal下载官网
  • 城阳网站开发产品推广渠道
  • 网站专题页优化关键词首页排名代做
  • 新开传奇网站刚开一秒第一区谷歌搜索引擎免费入口
  • 什么主题的网站容易做点百度seo排名查询
  • 赣州app开发广州seo公司品牌
  • 泰安网站制作十大it教育培训机构排名
  • 网上做游戏任务赚钱的网站营销技巧和营销方法
  • 交友网站开发术工业设计公司
  • 电商网站开发平台实验百度客户端在哪里打开
  • 网页设计与网站开发论文深圳百度快速排名优化
  • 南昌网站建设咨询搜索量查询百度指数
  • 建设工程造价员网站百度搜索竞价
  • 制作公司网页价钱合肥优化营商环境
  • 调兵山网站建设seo专员工资待遇
  • 响应式网站可以做缩放图吗广州seo网站管理
  • 来广营网站建设宁波seo优化排名
  • 外贸做网站用什么竞价推广是什么工作
  • 定制软件开发文案厦门seo优化外包公司
  • 品辰设计的网站谁做的怎么样做网站推广
  • 郑州市公安局建设路分局网站重庆网站排名推广