目錄
- 出錯現(xiàn)象
- 出錯原因
- 解決方案
出錯現(xiàn)象
這個(gè)報(bào)錯是我在用webpack+vue-loader的時(shí)候無法解析App.vue文件中<style>中css樣式導(dǎo)致的錯誤
- 源代碼
<template>
<div id="app">
<img alt="Vue logo" src="./assets/logo.png">
<HelloWorld msg="Welcome to Your Vue.js App"/>
</div>
</template>
<script>
import HelloWorld from './components/HelloWorld.vue'
export default {
name: 'App',
components: {
HelloWorld
}
}
</script>
<style>
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
</style>
- 報(bào)錯信息
ERROR in ./src/App.vue?vue&type=style&index=0&lang=css& (./node_modules/vue-loader/lib??vue-loader-options!./src/App.vue?vue&type=style&index=0&lang=css&) 20:0
Module parse failed: Unexpected character '#' (20:0)
File was processed with these loaders:

homework-error2.png
出錯原因
因?yàn)轫?xiàng)目中其他css文件是用less寫的,所以這個(gè)問題查閱了其他人的方法都沒有解決我的問題,后來我看這里默認(rèn)在vue里面css并沒有指定lang,所以應(yīng)該給css文件進(jìn)行單獨(dú)配置。
解決方案
在配置文件中進(jìn)行配置
module.exports = {
...
module: {
rules: [{
test: /\.vue$/,
use: 'vue-loader'
},{
test: /\.less$/,
use: [
'style-loader',
'css-loader',
'less-loader'
]
},{
test: /\.css$/,
use: [
'style-loader',
'css-loader',
]
}]
},
plugins: [
new VueLoaderPlugin()
]
}
it works~