首页 > 其他分享 >lit动态修改样式

lit动态修改样式

时间:2024-08-18 08:54:58浏览次数:8  
标签:styles count 修改 样式 lit color html import

src/my-counter.ts:

import { LitElement, css, html } from "lit";
import { customElement, property } from "lit/decorators.js";
import { styleMap } from "lit/directives/style-map.js";

@customElement("my-counter")
export class MyCounter extends LitElement {
	@property({ type: Number })
	count = 0;

	render() {
		const styles = { color: "" };
		if (this.count >= 0) {
			styles.color = "green";
		} else {
			styles.color = "red";
		}
		return html`
      <div>
        <button @click=${this._onDec} part="button"> - </button>
        count is: <span style=${styleMap(styles)}>${this.count}</span>
        <button @click=${this._onInc} part="button"> + </button>
      </div>
    `;
	}

	private _onDec() {
		this.count--;
	}

	private _onInc() {
		this.count++;
	}

	static styles = css`
    button {
      border-radius: 4px;
      border: 1px solid transparent;
      background-color: limegreen;
    }
  `;
}

declare global {
	interface HTMLElementTagNameMap {
		"my-counter": MyCounter;
	}
}

index.html:

<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <link rel="icon" type="image/svg+xml" href="/vite.svg" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Vite + Lit + TS</title>
    <script type="module" src="/src/my-counter.ts"></script>
  </head>
  <body>
    <my-counter count="5"></my-counter>
    <my-counter count="-5"></my-counter>
  </body>
</html>

标签:styles,count,修改,样式,lit,color,html,import
From: https://www.cnblogs.com/soarowl/p/18365264

相关文章

  • DzzOffice 修改未授权用户能调用组织部门信息问题
    问题描述无需登录,直接访问/index.php?mod=system&op=orgtree,出现组织部门信息解决方法一该方法是直接将system应用(系统组件)设置为仅允许登录用户使用文件:\dzz\system\config\config.php添加'allow_view'=>1,参数<?phpreturnarray('allow_robot'=>false,'allo......
  • DzzOffice修改权限判断方式解决另存为窗口新建文件无权限问题
    在执行另存为操作并选择文件与位置时,如提示无权限问题,此现象源于权限判断方式存在差异。为解决此问题,以在另存为窗口新建文件时提示无权限问题为例进行阐述。打开\dzz\system\fileselection\ajax.php文件。找到elseif($operation=='newIco'){//新建文件将perm_ch......
  • 使用 Python和 SQLite 打造一个简单的数据库浏览器
    在日常开发中,我们常常需要快速查看和操作SQLite数据库中的数据。虽然有许多现成的工具可以完成这一任务,但有时你可能想要一个更为简单、可定制的解决方案。在这篇博客中,我将带你一步步构建一个简单的SQLite数据库浏览器,它可以用来列出数据库中的表名、查看表的字段名、编写S......
  • SQL Server ManagementS tudio无法修改表,超时时间已到
      SQLServerManagementStudio无法修改表,超时时间已到在操作完成之前超时。  在修改表时,保存的时候显示:无法修改表,超时时间已到在操作完成之前超时时间已过或服务器未响应,这是执行时间设置过短的原因,可以修改一下设置便能把执行时间加长,以便有足够的时间执行完修改动作。......
  • 008、Vue3+TypeScript基础,数组和对象的响应式修改方法
    01、App.vue代码如下:<template><divclass="app"><h1>好好学习,天天向上</h1><Person/></div></template><script>//JS或TSimportPersonfrom'./view/Person.vue'exportdefault{//......
  • Splitting Items(Round 169)
    #include<bits/stdc++.h>#defineendl'\n'#defineintllusingll=longlong;typedefunsignedlonglongull;usingnamespacestd;voidGordenGhost();signedmain(){#ifdefGordenfreopen("in.txt","rt",stdin......
  • 【生日视频制作】飞机机身AE模板修改文字软件生成器教程特效素材【AE模板】
    飞机机身生日视频制作教程AE模板改文字特效广软件告生成器素材【生日视频制作】飞机机身AE模板修改文字软件生成器教程特效素材【AE模板】生日视频制作步骤:安装AE软件下载AE模板把AE模板导入AE软件修改图片或文字渲染出视频......
  • Debian修改了sshconfig之后仍无法root登录ssh
    1.检查/etc/ssh/sshd_config是否限制了登录session对话数等其他相关配置2.检查用户账户状态passwd-Sroot命令检查root用户的状态。假如返回:rootL03/28/20220999997-1rootL03/28/20220999997-1●L:表示密码被锁定。●03/28/2022:密码最后一次更改的......
  • utilman.exe 是 Windows 操作系统中的一个系统工具程序,全称为 Utility Manager。它的
    utilman.exe(实用工具管理器)在Windows系统中主要用于启动辅助功能工具,但它也曾经被发现存在一些安全漏洞。这些漏洞通常利用utilman.exe的特性进行权限提升或绕过安全机制。以下是一些已知的与utilman.exe相关的公开漏洞:1. CVE-2019-0708(BlueKeep)描述:这个漏洞影响了......
  • Ettercap 是一个用于网络嗅探和中间人攻击的开源工具,主要用于网络安全测试和分析。它
    Ettercap是一个用于网络嗅探和中间人攻击的开源工具,主要用于网络安全测试和分析。它支持多种平台,包括Linux、Windows和macOS。Ettercap可以用来监视、分析、和修改网络流量,通常用于测试和审计网络的安全性。以下是Ettercap的一些主要功能和特点:主要功能嗅探和分析网络......