# @appbaseio/vue-emotion 中文文档

规范地址：https://npmcn.com/package/%40appbaseio/vue-emotion/

版本：0\.6\.0-alpha\.6
npm 元数据更新时间：2023-04-19T07:30:42.224Z
中文译文更新时间：2026-11-06T13:41:52.648Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40appbaseio/vue-emotion
原文对照：https://npmcn.com/package/%40appbaseio/vue-emotion/?lang=original
项目主页：https://github.com/egoist/vue-emotion#readme
源码仓库：https://github.com/egoist/vue-emotion

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：17.6 kB，7 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：未声明
- 运行依赖：4 个
- peer 依赖：vue \>=3
- 首次发布：2019-08-12T21:22:59.698Z
- 最新版本发布：2023-01-09T14:21:46.624Z
- 近 30 天下载量：3079（2026-10-07 至 2026-11-05，npm 官方下载统计）
- 已发布版本数：8（近 12 个月 0 个）

## 中文简介

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

## 安装

```sh
npm install @appbaseio/vue-emotion
```

也可以使用：`pnpm add @appbaseio/vue-emotion`、`yarn add @appbaseio/vue-emotion`、`bun add @appbaseio/vue-emotion`

## README

# 情绪

[![NPM version](https://img.shields.io/npm/v/@egoist/vue-emotion.svg?style=flat)](https://npmjs.com/package/@egoist/vue-emotion) [![NPM downloads](https://img.shields.io/npm/dm/@egoist/vue-emotion.svg?style=flat)](https://npmjs.com/package/@egoist/vue-emotion) [![CircleCI](https://circleci.com/gh/egoist/vue-emotion/tree/master.svg?style=shield)](https://circleci.com/gh/egoist/vue-emotion/tree/master) [![donate](https://img.shields.io/badge/$-donate-ff69b4.svg?maxAge=2592000&style=flat)](https://patreon.com/egoist)

_[情绪](https://github.com/tkh44/emotion) 是下一代CSS-in-JS._

对Vue3的支持.

## 安装

```bash
yarn add @egoist/vue-emotion
```

## 目录

-   [使用量](https://npmcn.com/package/%40appbaseio/vue-emotion/#readme-usage)
    -   [他们](https://npmcn.com/package/%40appbaseio/vue-emotion/#readme-theming)
    -   [全局样式](https://npmcn.com/package/%40appbaseio/vue-emotion/#readme-global-styles)
    -   [服务器侧渲染](https://npmcn.com/package/%40appbaseio/vue-emotion/#readme-server-side-rendering)
-   [洞穴](https://npmcn.com/package/%40appbaseio/vue-emotion/#readme-caveats)
    -   [组件选择器不工作( 尚未)](https://npmcn.com/package/%40appbaseio/vue-emotion/#readme-component-selector-doesnt-work-yet)
-   [捐款](https://npmcn.com/package/%40appbaseio/vue-emotion/#readme-contributing)
-   [作者](https://npmcn.com/package/%40appbaseio/vue-emotion/#readme-author)

## 使用量

使用插件 :

```js
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')
```

创建您的样式组件 :

```js
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 (英语)](https://emotion.sh/) 更多的医生.

### 他们

使用 `provide/inject`数字 :

```js
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` 在通用应用代码中不建议使用,但是在我们找到更好的解决方案之前,把它当作工作.

### 全局样式

```vue
<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 :

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

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

## 洞穴

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

```js
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

## 作者

**情绪** © [电子化](https://github.com/egoist),在 [麻省理工学院](https://npmcn.com/package/%40appbaseio/vue-emotion/LICENSE) 执照.  
EGOIST在撰稿人的帮助下编写和维护[列表](https://github.com/egoist/vue-emotion/contributors)) (中文(简体) ).

> [github.com/egoist (英语)](https://github.com/egoist) • GitHub 软件 [@EGOIST(英语:](https://github.com/egoist) • 推特 [喜欢的](https://twitter.com/_egoistlily)

## 常见问题

### @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 和提交记录判断。

