# webcomponents-frame **Repository Path**: eljs/webcomponents-frame ## Basic Information - **Project Name**: webcomponents-frame - **Description**: Web Components增强框架。核心是一个组件基类,提供响应式状态、作用域插槽、作用域样式和声明式模板系统。采用Proxy监听+精准更新策略。轻松、快速编写Web Component,可扩展、可插拔和跨框架兼容。 - **Primary Language**: JavaScript - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-10-07 - **Last Updated**: 2025-10-18 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README 简体中文 | [English](https://github.com/892462856/webcomponents-frame) # Web components frame ### 介绍 这是一个基于 **Web Components** 的增强框架,具备以下特性: #### ✨ 核心功能 - 提供完整 MVVM 能力的组件基类 - 响应式状态管理 - 作用域插槽 - 作用域样式 - 声明式模板系统 #### 🚀 性能优势 - **Proxy 监听** + **细粒度更新** 策略 - **首创递归绑定** 机制 - 极致轻量与高效 #### 💡 框架特色 - 轻松快速编写 Web Component - 高度**可扩展**和**可插拔** - 完美**跨框架**兼容 ### 安装 npm install webcomponents-frame ### 指令集 - ***:if*** = "返回bool值的表达式/属性" - ***:else-if*** = "返回bool值的表达式/属性" - ***:else*** - ***:for*** = "(item,index,deep) in this.list" *(deep:递归绑定时的深度值;this.list:Array/Object/Number;item,index,deep可随意命名)* - ***:sub-for*** = "item.children" *(递归列表绑定)* - ***:show*** = "返回bool值的表达式/属性" - ***:model*** = "属性" - ***:slot-data*** = "obj" - ***:class*** = "{class1:true,class2:false}" - ***:style*** = "{borderWidth:'2px',borderColor:'#00f'}" - ***:attr*** = "this.propp/bool" *(element attrubite name)* - ***@event*** = "this.fu/expression" - ***@event.stop.prevent*** = "this.fu/expression" - ***:ref*** = "element ReferenceName" ### API - addEffector,nextTick,emit ### 生命周期 - attributeChangedCallback,constructor,initTemplate,connectedCallback,firstConnectedCallback,disconnectedCallback ### 使用示例 ##### *> main.js* ```javascript import { Component } from "webcomponents-frame" class TextComponent extends Component{ static observedAttributes = ['value','label','placeholder'] attributeChangedCallback(name, oldValue, newValue) { this[name] = newValue } constructor(templateId = 'cmpt-text-template'){ super(templateId) this.label = 'Label' this.labelSetting = { width: '4em', align: 'left' } this.value = '' this.placeholder = '' this.vertical = false this.styles = { borderRadius: '4px', borderColor: '#99f', borderSize: '8px', } } firstConnectedCallback(shadowRoot) { this.addEffector(()=>(this.value),{ fn:(newValue,oldValue)=>{ this.emit('change',newValue) } }) } get value(){} set value(v){} get label(){} set label(v){} get placeholder(){} set placeholder(v){} get labelSetting(){} set labelSetting(v){} get vertical(){} set vertical(v){} get styles(){} set styles(v){} } class TreeComponent extends Component{ constructor(templateId = 'cmpt-tree-template'){ super(templateId) this.list = [ {name:'广东省',code:1,children:[ {name:'广州市',code:11,children:[]}, {name:'深圳市',code:12,children:[]}, {name:'东莞市',code:13,children:[ {name:'虎门镇',code:131,children:[]}, {name:'厚街镇',code:132,children:[]} ]}, ]}, {name:'福建省',code:2,children:[]}, {name:'浙江省',code:3,children:[ {name:'杭州市',code:31,children:[]}, {name:'温州市',code:32,children:[]}, ]}, ] } get list(){} set list(v){} submitValue($event,{item,i,d}){ console.log($event,{item,i,d}) this.emit('select',item) } } class PageComponent extends Component{ constructor(templateId = 'cmpt-page-template'){ super(templateId) this.city = '' this.name = '' } get name(){} set name(v){} get city(){} set city(v){} setCity($event){ const obj = $event.detail this.city = obj.name } } customElements.define('cmpt-text', TextComponent) customElements.define('cmpt-tree', TreeComponent) customElements.define('cmpt-page', PageComponent) ``` ##### *> index.html* ```html Web Component Plus框架演示 ``` ### 教程/文档 - 访问 [http://www.wcfjs.com](http://www.wcfjs.com) ### 源码 - gitee [https://gitee.com/eljs/webcomponents-frame](https://gitee.com/eljs/webcomponents-frame) - github [https://github.com/892462856/webcomponents-frame](https://github.com/892462856/webcomponents-frame) ### License MIT