From 0f09245657419f57b0a0c361bcd597cde72093c7 Mon Sep 17 00:00:00 2001 From: yutent Date: Wed, 12 Jun 2024 19:02:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20when=E5=92=8Cwhich?= =?UTF-8?q?=E6=96=B9=E6=B3=95;=20=E5=90=8C=E6=97=B6mounted=E5=9B=9E?= =?UTF-8?q?=E8=B0=83=E6=97=B6=E6=9B=B4=E6=96=B0=E6=B8=B2=E6=9F=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/index.js | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 4b34040..72a65b7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "wkit", - "version": "1.11.5", + "version": "1.11.6", "type": "module", "description": "A library for building fast, lightweight web components.", "main": "dist/index.js", diff --git a/src/index.js b/src/index.js index 39e1947..e76c39d 100644 --- a/src/index.js +++ b/src/index.js @@ -59,6 +59,21 @@ export function styleMap(data = {}) { return output } +// 三元运算符的函数封装(只为了省个参数) +export function when(condition, trueCase = '', falseCase = '') { + return condition ? trueCase : falseCase +} + +// swicth语句的封装 +export function which(target, list = [], defaultCase = '') { + for (let [name, content] of list) { + if (target === name) { + return content + } + } + return defaultCase +} + export class Component extends HTMLElement { /** * 声明可监听变化的属性列表 @@ -387,6 +402,7 @@ export class Component extends HTMLElement { this.activated() } this.mounted() + this.$requestUpdate() }) } else { nextTick(_ => this.updated(props))