JSS (css in js) emotion库的使用

原文链接: JSS (css in js) emotion库的使用

上一篇: webgl 左手和右手坐标系转换

下一篇: ua-parser-js 判断设备类型和版本 针对不同的机型做降级

虽然灵活, 但是确实还是差点意思, 还是觉得元子类才是未来

几个库的对比

https://www.npmtrends.com/aphrodite-vs-emotion-vs-glamor-vs-jss-vs-radium-vs-styled-components-vs-linaria

up-e5f7903bc2f591846eeb9b8dc41d33ae1eb.png

这个应该也是一个不错的, 不过用着有点不太喜欢...

https://github.com/callstack/linaria

相比之下还是emotion看着好一点点...而且有支持vue的版本

https://github.com/emotion-js/emotion

https://github.com/egoist/vue-emotion

https://github.com/emotion-js/emotion/tree/master/packages/css

安装

p i  @emotion/css

基本上就是将css字符串转成动态类

up-e60e888bdd096c92f646c5a4c7b51dbf808.png

和vue scope类似, 有一个唯一的类名, 全局样式会导入, 按照一般的优先级, 这里使用id选择器设置了宽高, 所以只有北京色起作用了

up-456ff985d2a748cdbc8c24deff779dec2fb.png

<template>
  <div>
    <div id="box1"></div>
    <!-- https://github.com/emotion-js/emotion -->
    <!-- // https://github.com/callstack/linaria -->
    <!-- // https://www.npmtrends.com/aphrodite-vs-emotion-vs-glamor-vs-jss-vs-radium-vs-styled-components-vs-linaria -->
  </div>
</template>

<script lang="ts" setup>
import { css, injectGlobal } from "@emotion/css";
import { onMounted } from "vue";
onMounted(() => {
  const app = document.getElementById("box1")!;
  const myStyle = css`
    background: yellow;
    width: 100px;
    height: 100px;
  `;
  app.classList.add(myStyle);
  injectGlobal`
  body {
    width: 200px;
    height: 200px;
    background: deepskyblue;
  }
`;
});
</script>

<style></style>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值