代码拉取完成,页面将自动刷新
/**
* pages模版快速生成脚本,执行命令 npm run tep-d `文件名`
*/
const fs = require('fs')
const dirName = process.argv[2]
if (!dirName) {
console.log('文件夹名称不能为空!')
console.log('示例:npm run tep test')
process.exit(0)
}
// 页面模版
const indexTep = `<template>
<div></div>
</template>
<script>
export default {
name: '${dirName}',
data () {
return {
data: {}
}
},
methods: {
init () {}
},
activated () {
this.init()
},
mounted () {
this.init()
}
}
</script>
<style lang="less">
</style>
`
// api请求模版
const apiTep = `import {
getRequest,
postRequest,
deleteRequest,
putRequest
} from '@/libs/request'
export const ${dirName}List = params => {
return getRequest('/${dirName}', params)
}
export const ${dirName} = (id, params) => {
return getRequest('/${dirName}/' + id, params)
}
export const ${dirName}Create = params => {
return postRequest('/${dirName}/', params)
}
export const ${dirName}Delete = (id, params) => {
return deleteRequest('/${dirName}/' + id, params)
}
export const ${dirName}Deletes = params => {
return deleteRequest('/${dirName}/delete/', params)
}
export const ${dirName}Edit = (id, params) => {
return putRequest('/${dirName}/' + id, params)
}
`
fs.mkdirSync(`./src/view/${dirName}`) // mkdir $1
process.chdir(`./src/view/${dirName}`) // cd $1
fs.writeFileSync('index.vue', indexTep)
fs.writeFileSync('add.vue', indexTep)
process.chdir('../../') // cd $1
process.chdir('api')
fs.writeFileSync(`${dirName}.js`, apiTep)
console.log(`模版${dirName}已创建`)
process.exit(0)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。