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))