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

正品购物网站排行营销策划公司收费明细

正品购物网站排行,营销策划公司收费明细,深圳外贸公司电话,江苏徐州网站建设react-18.1.0,rc-easyui-1.2.9,babel-7.17.11 SPA还要处理的问题: (一)tabs切换事件通知 tabs切换时,自己的框架需要处理组件的生命周期,要有active/deactive,让组件能知道何时创…

react-18.1.0,rc-easyui-1.2.9,babel-7.17.11

SPA还要处理的问题:

(一)tabs切换事件通知

tabs切换时,自己的框架需要处理组件的生命周期,要有active/deactive,让组件能知道何时创建或清除一些资源的使用,比如setInterval/clearInterval。

赋予active/deactive事件通知,在tabs元件的onTabSelect/onTabUnselect事件处理就行了。如何通知?分两种情况:

(1)类式组件,让它定义一个function foil_onStateChanged(state)函数来接收。

page.likeButton.jsxclass Com_LikeButton extends React.Component {constructor(props) {console.log('likebutton constructor');super(props);this.state = { liked: false };}foil_onStateChanged(state){console.log('likebutton foil_onStateChanged',state);}render() {console.log('likeButton render',this.props);if (this.state.liked) {console.log(acroML.browserEngine.LCID);return t('&File');}return (<button onClick={() => this.setState({ liked: true })}>{t('&Edit')}</button>);}
}
export default Com_LikeButton;

(2)函数式组件,通过props参数传递。

page.timer.jsxexport default function COM_timer(props){console.log('page timer function:',props.foil.state);let [time,setTime]=React.useState(0);function getNow(){return time;}//timerID不参与渲染,用useReflet timerID=React.useRef(null);console.log('timerID:',timerID.current);if (props.foil.state=='create' || props.foil.state=='active'){if (timerID.current==null){console.log('start timer')timerID.current=setInterval(function(){console.log('timer:',time);time++;setTime(time);},1000);}}else if (props.foil.state=='deactive'||props.foil.state=='destroy'){if (timerID.current!=null){console.log('clear timerID:',timerID.current);clearInterval(timerID.current);timerID.current=null;}}return(<div><span>{t('&File')}</span><span>{getNow()}</span></div>)
}

虽然类组件有componentDidMount/componentWillUnmount两个事件来判断组件创建和销毁,但是函数式组件没有。如果框架要统一事件,最好把create/destroy事件也加进去。create可以在异步组件的componentDidMount处理,destroy就不能在动态元件的componentWillUnmount处理了,甚至不能在tabs的onTabClose事件处理,来不及了,虽然类组件可以,但函数式组件不会触发渲染重调用。

com.bizCom.jsximport { Suspense,Component } from 'react';
class Com_bizCom extends React.Component {constructor(props) {console.log('Com_bizCom constructor');super(props);props.foil.onStateChanged=this.foil_onStateChanged.bind(this);this.state={foil:{state:'create'}}}shouldComponentUpdate(nextProps, nextState) {//console.log(nextProps);//文件相同时不要再渲染,LCID改变后必须重渲染//if (nextProps.file && (nextProps.file === this.props.file)) return false;return true;}foil_onStateChanged(state){console.log('bizCom foil_onStateChanged',state);console.log(this.com);if (this.com.ref){//React.Component类组件可以通过函数通知状态if (this.com.ref.current.foil_onStateChanged){this.com.ref.current.foil_onStateChanged(state);}}else{//函数式组件只能通过proprs传递状态,然后bizCOM重渲染if (this.state.foil.state!=state){this.state.foil.state=state;this.com.props.foil.state=state;this.setState(this.state);}}}componentDidMount(){if (this.com.ref){//只需要组件元件通知一下create状态,函数元件第一渲染已经把create带到props.foil.statethis.com.ref.current.foil_onStateChanged('create');}}componentWillUnmount(){let self=this;console.log('bizCom componentWillUnmount',this.com.ref);//不在这里处理子函数式组件的销毁通知,来不及了,子函数式组件不会调用渲染//在easyui tab关闭前处理}render() {let self=this;console.log('Com_bizCom render',this.props);let file=this.props.file;if (!file) return null;/*let Com=React.lazy(function(){import函数不能加载jsxreturn import(file);});return(<Suspense><Com></Com></Suspense>)*/let obj=window.require(file);//console.log(obj);if (obj.__esModule===true) obj= obj.default;// console.log(typeof obj);// console.log(obj.prototype);console.log(self.com);let ops=null;if (self.com){ops=self.com.props;}else{ops={foil:{state:'create'}};if (obj.prototype && obj.prototype.isReactComponent){//类组件才有ref,函数式组件不能有refops.ref=React.createRef();}}let com=React.createElement(obj,ops);self.com=com;return com;}
}
export default Com_bizCom;

要在tabs的panel关闭前处理,查找easyui tabs源码,找到handleTabClose函数,hook一下:

com.right.jsx
............componentDidMount(){let self=this;console.log('right componentDidMount');console.log(this.ref_tabs.current.handleTabClose);//hook handleTabClose这个函数,在关闭panel前通知到bizCom里面的原件要销毁了做一些清理工作,比如清除timerlet fn=this.ref_tabs.current.handleTabClose;this.ref_tabs.current.handleTabClose=function(panel){console.log('handleTabClose',panel);let bizCom=self.getBizCom(panel);bizCom.props.foil.onStateChanged('destroy');//必须用异步,否则子函数式组件不会被调用刷新setTimeout(function(){fn.call(self.ref_tabs.current,panel);}, 0);}}

(二)主界面切换显示的语言

只要在根原件把LCID设置为响应式,改变时,tabs各个组件会刷新。

com.root.jsximport Com_Main from './com.main.jsx';
// import Com_acroMLStub from './com.acroML.stub.jsx';
export default function COM_Root(){console.log('root',acroML.browserEngine.LCID);let [LCID,setLCID]=React.useState(acroML.browserEngine.LCID);acroML.browserEngine.switchLanguage=function(){//console.log(acroML.browserEngine.LCID);setLCID(acroML.browserEngine.LCID);//console.log(LCID);}//<Com_acroMLStub>return(<Com_Main></Com_Main>);
}

http://www.hrbkazy.com/news/48007.html

相关文章:

  • 网站开发与设计500强公司网站的营销推广方案
  • 做网站 需要多少钱廊坊关键词优化排名
  • 可以做软件的网站有哪些内容吗网站免费制作平台
  • 新手如何做移动端网站上海平台推广的公司
  • 温州集团网站建设2023年8月新冠又来了
  • wordpress导出导入数据库网页优化方法
  • 电商网站设计公司浙江网站推广运营
  • 网站建设都需要那些材料线上电脑培训班
  • 网站url和网站域名seo如何优化网站推广
  • 怎么让自己的网站泉州网站seo外包公司
  • 常州地区做网站网站出租三级域名费用
  • 网站建设财务项目管理制度百度优化关键词
  • 贾汪网站开发太原百度seo排名软件
  • 网站开发语言和数据库有几种百度网站关键词优化
  • 做网站要学会那些seo词条
  • 私密浏览器免费版在线看视频如何进行网站性能优化?
  • 企业内部网站源码微信seo什么意思
  • 在国外做盗版电影网站做seo的公司
  • wordpress评论时选填百度首页优化排名
  • 河北省住建和城乡建设厅网站国内seo公司哪家最好
  • 山东住房和建设厅网站首页今日热点新闻视频
  • 做排行榜的网站高端企业网站定制公司
  • 寻找做网站的公司自动秒收录网
  • 网站建设达到什么水平如何推广微信公众号
  • 阿里OSS做网站图库费用旺道seo营销软件
  • 织梦做分类信息系统网站seo工资服务
  • 青海公司网站建设哪家好环球资源外贸平台免费
  • it培训机构排行榜wordpress seo教程
  • 推广做网站莱芜百度人工智能开放平台
  • 24小时自动发货网站建设产品推广策划