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

es6 函数解构

对象的解构赋值是内部机制,先找回同名属性,再赋值给对应的变量,真正被赋值的是后者。

let node = {type:'Identifier',name:'foo',loc:{start:{line:1,column:1},end:{line:1,column:4}},method:function(){console.log('method');},range:[0,3]
};
//
let {loc:{start:start1},range:[startIndex]
} = node;
//将loc.start 解构值赋给一个start1变量
console.log('@@@@',start1,startIndex); 
//将mehtod 函数解构赋给method1 函数变量
let {method: method1    
} = node;
method1()

不难理解

<template>
<a-upload name="file" :showUploadList="false" :customRequest="(file) => handleImportXls(file, getImportUrl, reload)"><a-button preIcon="ant-design:import-outlined" type="primary">导入</a-button></a-upload><JImportModal @register="registerModalJimport" :url="getImportUrl" online />
</template><script lang="ts" setup>
const [registerModalJimport, {openModal: openModalJimport }] = useModal();function handleImport() {//调用函数openModal: <T = any>(visible = true, data?: T, openOnSet = true): void//设置visible =true 显示弹出框openModalJimport(true);}</script>

useModal.ts


export function useModal(): UseModalReturnType {const modal = ref<Nullable<ModalMethods>>(null);const loaded = ref<Nullable<boolean>>(false);const uid = ref<string>('');function register(modalMethod: ModalMethods, uuid: string) {if (!getCurrentInstance()) {throw new Error('useModal() can only be used inside setup() or functional components!');}uid.value = uuid;isProdMode() &&onUnmounted(() => {modal.value = null;loaded.value = false;dataTransfer[unref(uid)] = null;});if (unref(loaded) && isProdMode() && modalMethod === unref(modal)) return;modal.value = modalMethod;loaded.value = true;modalMethod.emitVisible = (visible: boolean, uid: number) => {visibleData[uid] = visible;};}const getInstance = () => {const instance = unref(modal);if (!instance) {error('useModal instance is undefined!');}return instance;};const methods: ReturnMethods = {setModalProps: (props: Partial<ModalProps>): void => {getInstance()?.setModalProps(props);},getVisible: computed((): boolean => {return visibleData[~~unref(uid)];}),getOpen: computed((): boolean => {return visibleData[~~unref(uid)];}),redoModalHeight: () => {getInstance()?.redoModalHeight?.();},// visible 是否显示	openModal: <T = any>(visible = true, data?: T, openOnSet = true): void => {getInstance()?.setModalProps({open: visible,});if (!data) return;const id = unref(uid);if (openOnSet) {dataTransfer[id] = null;dataTransfer[id] = toRaw(data);return;}const equal = isEqual(toRaw(dataTransfer[id]), toRaw(data));if (!equal) {dataTransfer[id] = toRaw(data);}},closeModal: () => {// update-begin--author:liaozhiyang---date:20231218---for:【QQYUN-6366】升级到antd4.xgetInstance()?.setModalProps({ open: false });// update-end--author:liaozhiyang---date:20231218---for:【QQYUN-6366】升级到antd4.x},};return [register, methods];
}

相关文章:

  • 不打架的协议互通,modbus转profibus网关的总线的高效互通方案
  • 通用大数据可视化展示平台模板 – 免费HTML源码
  • 解锁 AI 开发新境界:OPE Pod 开放平台深度解析
  • 云服务器系统盘满了,但是其他正常,是否可能是被攻击了
  • BSS / OSS 是什么
  • 软件测试环境搭建及测试过程
  • 软件测试的潜力与挑战:从“质量守门员”到“工程效能催化剂”的进化
  • [Vue组件]半环进度显示器
  • 三十一、面向对象底层逻辑-SpringMVC九大组件之RequestToViewNameTranslator接口设计哲学
  • pycharm找不到高版本conda问题
  • window 显示驱动开发-处理 E_INVALIDARG 返回值
  • Vert.x学习笔记-什么是Context
  • Django数据库连接报错 django.db.utils.NotSupportedError: MySQL 8 or later is required
  • 系统思考:心智模式与业务创新
  • 增程与插混技术战略
  • node-DeepResearch开源ai程序用于深入调查查询,继续搜索、阅读网页、推理,直到找到答案
  • VMware安装Ubuntu实战分享大纲
  • 类和对象(中1)
  • 在 Linux 中让 ​​Gunicorn​​ 在后台运行(作为守护进程),有几种常用方法:
  • 论文笔记:Towards Explainable Traffic Flow Prediction with Large Language Models
  • 专注合肥网站建设/专业seo站长工具全面查询网站
  • 公司注册地址异常如何处理/站长工具seo综合查询广告
  • 沈阳建设网站/广东疫情防控措施
  • 常州的做网站的公司排名/微信营销策略有哪些
  • 做网站招商需要具备什么/短视频seo推广隐迅推专业
  • 上海建站网站的企业/深圳做网站