Node.js/nuxt/css module:修订间差异
来自康健生活
| (未显示同一用户的3个中间版本) | |||
| 第1行: | 第1行: | ||
== 引言 == | |||
[https://github.com/css-modules/css-modules css-modules] | |||
== 配置 == | == 配置 == | ||
配置文件,网上众说纷纭,把我看得笑哭了,配置文件要两步走,一是看官方文档(其实内容很片面),而是看官方示例([https://github.com/nuxt/nuxt.js/blob/19e68e770c1d50a97cef7743e93e4e8c6aaed80c/packages/config/src/config/build.js 示例一]、[https://github.com/nuxt/nuxt.js/blob/19e68e770c1d50a97cef7743e93e4e8c6aaed80c/packages/config/test/config/__snapshots__/index.test.js.snap 示例二]) | |||
{{hc|nuxt.config.js|<syntaxhighlight lang="javascript"> | {{hc|nuxt.config.js|<syntaxhighlight lang="javascript"> | ||
{ | /*! | ||
loaders:{ | * nuxt 配置文件 | ||
* @auther kangkk | |||
*/ | |||
... | |||
const config = { | |||
mode: 'universal', | |||
... | |||
/* | |||
** Build configuration | |||
*/ | |||
build: { | |||
loaders: { | |||
cssModules: { | |||
modules: { | |||
localIdentName: "[path][name]-[local]-[hash:5]" | |||
} | |||
}, | |||
}, | }, | ||
... | |||
} | |||
export default config}</syntaxhighlight>}} | |||
}</syntaxhighlight>}} | |||
在配置文件的[https://zh.nuxtjs.org/api/configuration-build/#loaderscss-and-loaderscssmodules 说明文档]中标注了: | 在配置文件的[https://zh.nuxtjs.org/api/configuration-build/#loaderscss-and-loaderscssmodules 说明文档]中标注了: | ||
| 第43行: | 第45行: | ||
... | ... | ||
</div> | </div> | ||
<button :class="{ | <button :class="{ | ||
[$header.button]: true, | [$header.button]: true, | ||
}">登录</button> | }">登录</button> | ||
| 第56行: | 第58行: | ||
} | } | ||
</script></syntaxhighlight> | </script></syntaxhighlight> | ||
=== module === | |||
<syntaxhighlight lang="html5"> | |||
<template> | |||
<!-- header start--> | |||
<el-header :class="{ [headerStyle.header]: true }"> | |||
<div class="header-body"> | |||
... | |||
</template> | |||
<style module="headerStyle" lang="scss">@import "./header.scss";</style></syntaxhighlight> | |||