stenciljs 学习一 web 组件开发

stenciljs 介绍参考官方网站,或者 https://www.cnblogs.com/rongfengliang/p/9706542.html

创建项目

  • 使用脚手架工具
npm init stencil


  • 更新版本(实际上是bug fix)
npm install @stencil/core@latest --save-exact

效果

  • 项目结构

构建&&测试

  • 构建
yarn start // 包含运行测试
yarn build 构建组件
  • 效果

    使用yarn start 同时进行测试

demo 组件说明

使用tsx 进行开发,类似react 的生命周期模型,类似ng 的开发方式(装饰器,注解。。。)

import { Component, Prop } from '@stencil/core';

@Component({
tag: 'my-component',
styleUrl: 'my-component.css',
shadow: true
})
export class MyComponent {

@Prop() first: string;
@Prop() last: string;

render() {
return (
<div>
Hello, World! I'm {this.first} {this.last}
</div>
);
}
}

添加css

div {
font-size: 50px;
background-color: cadetblue;
}

编译效果

参考资料

https://stenciljs.com/docs/getting-started

posted on   荣锋亮  阅读(1040)  评论(0编辑  收藏  举报

编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2017-09-26 envoy  功能介绍
2017-09-26 envoy 测试试用

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示