Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.8k views
in Technique[技术] by (71.8m points)

TypeScript ,import引入css样式,可以用,但是值全是undefined

popup.css

.yp-popup {
  position: fixed;
  z-index: 999;
  border: 1px solid #d9d9d9;
}

popup.css.d.ts

declare const styles: {
  readonly 'yp-popup': string
}

export default styles

popup.ts

import styles from './popup.css'
function popup() {
  return styles['yp-popup']
}
export default popup

console.log(popup) 结果如下:

popup() {
  return _popup_css__WEBPACK_IMPORTED_MODULE_0___default.a['yp-popup'];
}

console.log(popup()) 结果为undefined

请教大神,这个哪里不对?万分感谢!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

看下你的 webpack 的配置,通常 css 和 css module 的解析规则不同,css module 通常需要配置 css-loader modules: true,也有可能你要用 styles.module.css 引入


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...