小编Dmi*_*kin的帖子

Vue + TypeScript + CSS 模块

我有 SFC(单文件 vue 组件),它使用 TypeScript、渲染函数和 CSS 模块

<script lang="ts">
import Vue from 'vue';

export default Vue.extend({
  props: {
    mode: {
      type: String,
      default: 'td', // or th
    },
  },
  render(h) {
    return h('tr', [
      'preview',
      'name',
      'price',
      'count',
      'delete',
    ].map(col => h(this.mode, { class: this.$style[col] },
      this.$slots[col])));
  },
});
</script>

<style lang="stylus" module>
.preview
  display none

.delete
  text-align center

@media (min-width 768px)
  .preview
    display table-row
</style>
Run Code Online (Sandbox Code Playgroud)

我从 TypeScript 收到错误:

ERROR in /home/oks/apps/shop/src/components/CartRow.vue
18:45 Property '$style' does not exist on type …
Run Code Online (Sandbox Code Playgroud)

typescript vue.js css-modules

7
推荐指数
1
解决办法
2075
查看次数

标签 统计

css-modules ×1

typescript ×1

vue.js ×1