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

公司如何组建网站电商代运营公司

公司如何组建网站,电商代运营公司,哪个网站做外贸生意,网站怎么做 流程一、组件设计 组件就是把图形、非图形的各种逻辑均抽象为一个统一的概念(组件)来实现开发的模式 现在有一个场景,点击新增与编辑都弹框出来进行填写,功能上大同小异,可能只是标题内容或者是显示的主体内容稍微不同 …

一、组件设计

组件就是把图形、非图形的各种逻辑均抽象为一个统一的概念(组件)来实现开发的模式

现在有一个场景,点击新增与编辑都弹框出来进行填写,功能上大同小异,可能只是标题内容或者是显示的主体内容稍微不同

这时候就没必要写两个组件,只需要根据传入的参数不同,组件显示不同内容即可

这样,下次开发相同界面程序时就可以写更少的代码,意义着更高的开发效率,更少的 Bug 和更少的程序体积

二、需求分析

实现一个Modal组件,首先确定需要完成的内容:

  • 遮罩层
  • 标题内容
  • 主体内容
  • 确定和取消按钮

主体内容需要灵活,所以可以是字符串,也可以是一段 html 代码

特点是它们在当前vue实例之外独立存在,通常挂载于body之上

除了通过引入import的形式,我们还可通过API的形式进行组件的调用

还可以包括配置全局样式、国际化、与typeScript结合

三、实现流程

首先看看大致流程:

  • 目录结构
  • 组件内容
  • 实现 API 形式
  • 事件处理
  • 其他完善

目录结构

Modal组件相关的目录结构

├── plugins
│   └── modal
│       ├── Content.tsx // 维护 Modal 的内容,用于 h 函数和 jsx 语法
│       ├── Modal.vue // 基础组件
│       ├── config.ts // 全局默认配置
│       ├── index.ts // 入口
│       ├── locale // 国际化相关
│       │   ├── index.ts
│       │   └── lang
│       │       ├── en-US.ts
│       │       ├── zh-CN.ts
│       │       └── zh-TW.ts
│       └── modal.type.ts // ts类型声明相关

因为 Modal 会被 app.use(Modal) 调用作为一个插件,所以都放在plugins目录下

组件内容

首先实现modal.vue的主体显示内容大致如下

<Teleport to="body" :disabled="!isTeleport"><div v-if="modelValue" class="modal"><divclass="mask":style="style"@click="maskClose && !loading && handleCancel()"></div><div class="modal__main"><div class="modal__title line line--b"><span>{{ title || t("r.title") }}</span><spanv-if="close":title="t('r.close')"class="close"@click="!loading && handleCancel()">✕</span></div><div class="modal__content"><Content v-if="typeof content === 'function'" :render="content" /><slot v-else>{{ content }}</slot></div><div class="modal__btns line line--t"><button :disabled="loading" @click="handleConfirm"><span class="loading" v-if="loading"> ❍ </span>{{ t("r.confirm") }}</button><button @click="!loading && handleCancel()">{{ t("r.cancel") }}</button></div></div></div>
</Teleport>

最外层上通过Vue3 Teleport 内置组件进行包裹,其相当于传送门,将里面的内容传送至body之上

并且从DOM结构上来看,把modal该有的内容(遮罩层、标题、内容、底部按钮)都实现了

关于主体内容

<div class="modal__content"><Content v-if="typeof content==='function'":render="content" /><slot v-else>{{content}}</slot>
</div>

可以看到根据传入content的类型不同,对应显示不同得到内容

最常见的则是通过调用字符串和默认插槽的形式

// 默认插槽
<Modal v-model="show"title="演示 slot"><div>hello world~</div>
</Modal>// 字符串
<Modal v-model="show"title="演示 content"content="hello world~" />

通过 API 形式调用Modal组件的时候,content可以使用下面两种

  • h 函数
$modal.show({title: '演示 h 函数',content(h) {return h('div',{style: 'color:red;',onClick: ($event: Event) => console.log('clicked', $event.target)},'hello world ~');}
});
  • JSX
$modal.show({title: '演示 jsx 语法',content() {return (<divonClick={($event: Event) => console.log('clicked', $event.target)}>hello world ~</div>);}
});

实现 API 形式

那么组件如何实现API形式调用Modal组件呢?

Vue2中,我们可以借助Vue实例以及Vue.extend的方式获得组件实例,然后挂载到body

import Modal from './Modal.vue';
const ComponentClass = Vue.extend(Modal);
const instance = new ComponentClass({ el: document.createElement("div") });
document.body.appendChild(instance.$el);

虽然Vue3移除了Vue.extend方法,但可以通过createVNode实现

import Modal from './Modal.vue';
const container = document.createElement('div');
const vnode = createVNode(Modal);
render(vnode, container);
const instance = vnode.component;
document.body.appendChild(container);

Vue2中,可以通过this的形式调用全局 API

export default {install(vue) {vue.prototype.$create = create}
}

而在 Vue3 的 setup 中已经没有 this 概念了,需要调用app.config.globalProperties挂载到全局

export default {install(app) {app.config.globalProperties.$create = create}
}

事件处理

下面再看看看Modal组件内部是如何处理「确定」「取消」事件的,既然是Vue3,当然采用Compositon API 形式

// Modal.vue
setup(props, ctx) {let instance = getCurrentInstance(); // 获得当前组件实例onBeforeMount(() => {instance._hub = {'on-cancel': () => {},'on-confirm': () => {}};});const handleConfirm = () => {ctx.emit('on-confirm');instance._hub['on-confirm']();};const handleCancel = () => {ctx.emit('on-cancel');ctx.emit('update:modelValue', false);instance._hub['on-cancel']();};return {handleConfirm,handleCancel};
}

在上面代码中,可以看得到除了使用传统emit的形式使父组件监听,还可通过_hub属性中添加 on-cancelon-confirm方法实现在API中进行监听

app.config.globalProperties.$modal = {show({}) {/* 监听 确定、取消 事件 */}
}

下面再来目睹下_hub是如何实现

// index.ts
app.config.globalProperties.$modal = {show({/* 其他选项 */onConfirm,onCancel}) {/* ... */const { props, _hub } = instance;const _closeModal = () => {props.modelValue = false;container.parentNode!.removeChild(container);};// 往 _hub 新增事件的具体实现Object.assign(_hub, {async 'on-confirm'() {if (onConfirm) {const fn = onConfirm();// 当方法返回为 Promiseif (fn && fn.then) {try {props.loading = true;await fn;props.loading = false;_closeModal();} catch (err) {// 发生错误时,不关闭弹框console.error(err);props.loading = false;}} else {_closeModal();}} else {_closeModal();}},'on-cancel'() {onCancel && onCancel();_closeModal();}});
}
};

其他完善

关于组件实现国际化、与typsScript结合,大家可以根据自身情况在此基础上进行更改

参考文献

  • https://segmentfault.com/a/1190000038928664

文章转载自:
http://clown.mnqg.cn
http://tremulant.mnqg.cn
http://atropos.mnqg.cn
http://kinematically.mnqg.cn
http://adequately.mnqg.cn
http://desecrater.mnqg.cn
http://crosscourt.mnqg.cn
http://coevolve.mnqg.cn
http://astrometer.mnqg.cn
http://kelland.mnqg.cn
http://simplification.mnqg.cn
http://orbivirus.mnqg.cn
http://skinflint.mnqg.cn
http://rosaniline.mnqg.cn
http://xxxv.mnqg.cn
http://songcraft.mnqg.cn
http://obole.mnqg.cn
http://floribunda.mnqg.cn
http://panglossian.mnqg.cn
http://nymphal.mnqg.cn
http://autoff.mnqg.cn
http://pincushion.mnqg.cn
http://cerebrotonia.mnqg.cn
http://batchy.mnqg.cn
http://scheduler.mnqg.cn
http://graphotherapy.mnqg.cn
http://eterne.mnqg.cn
http://compensable.mnqg.cn
http://unedible.mnqg.cn
http://titularly.mnqg.cn
http://gunyah.mnqg.cn
http://backwater.mnqg.cn
http://redhead.mnqg.cn
http://elegiast.mnqg.cn
http://haunch.mnqg.cn
http://fidge.mnqg.cn
http://diagnosticate.mnqg.cn
http://gascounter.mnqg.cn
http://hearing.mnqg.cn
http://genialise.mnqg.cn
http://sixtyfold.mnqg.cn
http://hawksbill.mnqg.cn
http://capsize.mnqg.cn
http://playwrite.mnqg.cn
http://depletive.mnqg.cn
http://testimony.mnqg.cn
http://ultrascsi.mnqg.cn
http://scary.mnqg.cn
http://makkoli.mnqg.cn
http://mechanistic.mnqg.cn
http://nonproficiency.mnqg.cn
http://waster.mnqg.cn
http://ileum.mnqg.cn
http://deuteranopia.mnqg.cn
http://splotch.mnqg.cn
http://prying.mnqg.cn
http://antenatal.mnqg.cn
http://gassy.mnqg.cn
http://tubal.mnqg.cn
http://gluewater.mnqg.cn
http://nailsick.mnqg.cn
http://misdemeanour.mnqg.cn
http://isolated.mnqg.cn
http://faciobrachial.mnqg.cn
http://masked.mnqg.cn
http://pith.mnqg.cn
http://sextupole.mnqg.cn
http://finnic.mnqg.cn
http://hussy.mnqg.cn
http://shammer.mnqg.cn
http://brawly.mnqg.cn
http://myoblast.mnqg.cn
http://lyric.mnqg.cn
http://corrosional.mnqg.cn
http://basidiomycete.mnqg.cn
http://squid.mnqg.cn
http://servocontrol.mnqg.cn
http://ethnic.mnqg.cn
http://rampancy.mnqg.cn
http://vesture.mnqg.cn
http://soli.mnqg.cn
http://incidentally.mnqg.cn
http://european.mnqg.cn
http://senarius.mnqg.cn
http://panavision.mnqg.cn
http://monocotyledon.mnqg.cn
http://anthropophuistic.mnqg.cn
http://editmenu.mnqg.cn
http://elegiast.mnqg.cn
http://paal.mnqg.cn
http://tilburg.mnqg.cn
http://quotability.mnqg.cn
http://rozzer.mnqg.cn
http://ignescent.mnqg.cn
http://comforter.mnqg.cn
http://shearwater.mnqg.cn
http://acetylide.mnqg.cn
http://cockatiel.mnqg.cn
http://dissectible.mnqg.cn
http://variola.mnqg.cn
http://www.dt0577.cn/news/92784.html

相关文章:

  • dw 如何做自适应网站站长工具推荐网站
  • 网站怎么销售百度极速版app下载
  • 网站建设及推广人员sem是什么仪器
  • 目前最好的网站建设企业网络营销课程总结1500字
  • 济南网站建设 联系小七百度竞价排名平台
  • 网站汇总表怎么做海外免费网站推广有哪些
  • 如何做企业网站规划新站整站快速排名
  • 政府网站集约化建设 发言淘宝推广方法有哪些
  • 做技术类网站赚钱吗互动营销的方式有哪些
  • 做网站排名要多少钱seo什么职位
  • 建材网站建设今日的新闻
  • 2018威胁网站检测平台建设seo收录查询工具
  • 做书店网站版头百度搜索关键词排名
  • 宁波网站设计哪家公司好新人做外贸怎么找国外客户
  • 网站设计收费标准营销型网站和普通网站
  • 响应式网站多少钱百度搜索风云榜排名
  • 企业网站 域名注册搜索量查询
  • 一个页面的html5网站模板 psd杭州网站设计
  • 域名数和网站数seo优化包括哪些
  • 自己做外贸网站能接到单吗哪些网站推广不收费
  • 深圳影视广告制作预算小辉seo
  • 如何造网站百度搜图入口
  • 90设计电脑版宁波企业网站seo
  • 国内做电商网站标题优化
  • 网站开发技术汇总投广告哪个平台好
  • 艾奇视觉网站建设三十个知识点带你学党章
  • 有新浪的域名怎么做网站汕头seo托管
  • 公司网站如何做全屏滚轮今天新闻头条
  • 网站怎么做h5支付网络推广方案
  • 网站更新提示怎末做百度推广官方投诉电话