npm install vue-auto-name-loader -D
Modify webpack: vue-loader
related configuration
module.exports = {
...
module: {
rules: [
...
{
test: /\.vue$/,
loader: 'vue-loader',
options: {
loaders: {
js: [
{ loader: 'vue-auto-name-loader', options: { prefix: 'what' } }
]
}
}
},
...
]
}
...
}
Before conversion
<template>
...
</template>
<script>
export default {
data() {
return {
name: 1344
}
}
}
</script>
<style>
...
</style>
After conversion
<template>
...
</template>
<script>
export default {
name: 'what-1',
data() {
return {
name: 1344
}
}
}
</script>
<style>
...
</style>
- prefix:name前缀设置,默认为空