@appbaseio/vue-emotion

中文文档
0.6.0-alpha.6发布于 2023/01/09MITESM + CJS近 30 天下载 3079

与Vue.js无缝地使用情感(CSS-in-JS)

中文使用文档
文档目录10 节
  1. 安装
  2. 目录
  3. 使用量
  4. 他们
  5. 全局样式
  6. 服务器侧渲染
  7. 洞穴
  8. 组件选择器不工作( 尚未)
  9. 捐款
  10. 作者

情绪

NPM version NPM downloads CircleCI donate

情绪 是下一代CSS-in-JS.

对Vue3的支持.

安装

yarn add @egoist/vue-emotion

目录

使用量

使用插件 :

import { VueEmotion } from '@egoist/vue-emotion'

import { createApp } from 'vue'
import App from './App.vue'
import { VueEmotion } from '../../src/index'

import './index.css'

const app = createApp(App, { mixins: [VueEmotion] })

app.mount('#app')

创建您的样式组件 :

import { styled } from '@egoist/vue-emotion'

const Button = styled('button')`
  font-size: 15px;
`

const PinkButton = styled(Button)`
  color: hotpink;
`

const Component = {
  components: {
    Button,
    PinkButton,
  },
  setup() {
    return () => {
      return (
        <div>
          <Button>normal button</Button>
          <PinkButton>pink button</PinkButton>
        </div>
      )
    }
  }
}

参见 https://emotion.sh (英语) 更多的医生.

他们

使用 provide/inject数字 :

const Component = {
  components: {
    Button,
    PinkButton,
  },
  provide() {
    return {
      theme: this.theme
    }
  },
  data() {
    return {
      theme: 'dark'
    }
  },
  setup() {
    return () => {
      const Button = styled('button')`
        color: ${props => (props.theme === 'dark' ? 'white' : 'black')};
      `
       return <Button>Hello</Button>
    }
  }
}

这我知道 provide/inject 在通用应用代码中不建议使用,但是在我们找到更好的解决方案之前,把它当作工作.

全局样式

<template>
  <div id="app">
    <GlobalStyle />
    <!-- rest of your app -->
  </div>
</template>

<script>
import { createGlobalStyle } from '@egoist/vue-emotion'

const GlobalStyle = createGlobalStyle`
  body {
    background: red;
  }
`

export default {
  components: {
    GlobalStyle
  }
}
</script>

服务器侧渲染

您可以在服务器侧渲染时提取这样关键的 CSS :

const { renderStyle } = require('@egoist/vue-emotion/server')

// `html` is the rendered HTML by vue-server-renderer
const style = renderStyle(html)
// <style>...</style>

洞穴

组件选择器不工作( 尚未)

const Container = styled.div`
  ${Button} {
    color: red;
  }
`

捐款

  1. 叉开它!
  2. 创建您的特性分支 : git checkout -b my-new-feature
  3. 提交更改 : git commit -am 'Add some feature'
  4. 推到树枝上: git push origin my-new-feature
  5. 提交拉动请求 : D

作者

情绪 © 电子化,在 麻省理工学院 执照.
EGOIST在撰稿人的帮助下编写和维护列表) (中文(简体) ).

github.com/egoist (英语) • GitHub 软件 @EGOIST(英语: • 推特 喜欢的

版本与发布记录

@appbaseio/vue-emotion 共发布 8 个版本,首次发布于 2019/08/13;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.6.0-alpha.6latest2023/01/093 年前
0.6.0-alpha.52023/01/093 年前
0.6.0-alpha.42023/01/093 年前
0.6.0-alpha.32022/12/303 年前
0.6.0-alpha.22022/12/293 年前
0.6.0-alpha.12022/12/293 年前

关于 @appbaseio/vue-emotion 的常见问题

@appbaseio/vue-emotion 是什么?

与Vue.js无缝地使用情感(CSS-in-JS)

如何安装 @appbaseio/vue-emotion?

在项目目录运行 npm install @appbaseio/vue-emotion,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:vue(>=3)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@appbaseio/vue-emotion 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/appbaseio__vue-emotion 是否存在。

@appbaseio/vue-emotion 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@appbaseio/vue-emotion 可以商用吗?

@appbaseio/vue-emotion 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@appbaseio/vue-emotion 的下载量有多少?

根据 npm 官方下载统计,@appbaseio/vue-emotion 在 2026/10/07 – 2026/11/05 这 30 天内被下载 3,079 次,日均约 103 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@appbaseio/vue-emotion 还在维护吗?

最新版本 0.6.0-alpha.6 发布于 2023/01/09(3 年前);至今共发布 8 个版本,其中过去 12 个月发布了 0 个;首次发布于 2019/08/13。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。