<el-dialog
title="添加分类"
:visible.sync="addCateDialogVisible"
width="50%"
>
<!-- 添加分类表单 -->
<el-form
:model="addCateForm"
:rules="addCateFormRules"
ref="addCateFormRef"
label-width="100px"
>
<el-form-item label="分类名称:" prop="cat_name">
<el-input v-model="addCateForm.cat_name"></el-input>
</el-form-item>
<el-form-item label="父级分类:"> </el-form-item>
</el-form>
<span slot="footer" class="dialog-footer">
<el-button @click="addCateDialogVisible = false">取 消</el-button>
<el-button type="primary" @click="addCateDialogVisible = false"
>确 定</el-button
>
</span>
</el-dialog>
export default {
data() {
return {
querInfo: {
type: 3,
pagenum: 1,
pagesize: 5,
},
// 商品分类数据列表为空
cateList: [],
total: 0,
columns: [
{
label: '分类名称 ',
prop: 'cat_name',
},
{
label: '是否有效',
// 表示,当前列为模板列
type: 'template',
template: 'isok',
},
{
label: '排序',
// 表示,当前列为模板列
type: 'template',
template: 'order',
},
{
label: '操作',
// 表示,当前列为模板列
type: 'template',
template: 'opt',
},
],
// 控制添加对话框的显示隐藏
addCateDialogVisible: false,
addCateForm: {
// 将要添加的分类名称
cat_name: '',
// 父级分类的id
cat_pid: 0,
// 分类的等级默认为一级分类
cat_level: 0,
},
// 父级分类的列表
parentCateList: [],
// 校验规则
addCateFormRules: {
cat_name: [
{ required: true, message: '请输入分类名称', trigger: 'blur' },
],
},
}
},
created() {
this.getcateList()
},
methods: {
// 获取商品分类数据
async getcateList() {
const { data: res } = await this.$http.get('categories', {
params: this.querInfo,
})
if (res.meta.status !== 200) {
return this.$message.error('获取商品分类失败')
}
console.log(res.data)
this.cateList = res.data.result
this.total = res.data.total
},
// 监听pagesize改变
handleSizeChange(newSize) {
this.querInfo.pagesize = newSize
this.getcateList()
},
// 监听pagenum改变
handleCurrentChange(newPage) {
this.querInfo.pagenum = newPage
this.getcateList()
},
// 点击按钮,展示添加分类的对话框
shoeAddCateDialog() {
// 获取父级分类的数据列表
this.getParentCateList()
// 然后再展示对话框
this.addCateDialogVisible = true
},
// 获取父级分类的数据列表
async getParentCateList() {
const { data: res } = await this.$http.get('categories', {
params: { type: 2 },
})
if (res.meta.status !== 200) {
return this.$message.error('获取父级分类失败!')
}
this.parentCateList = res.data
// console.log(res.data)
},
},
}
<el-form-item label="父级分类:"> </el-form-item> 这里面没使用prop绑定字段呢
是否可以更详细描述一下问题,比如什么控件显示不正常,代码大概在第几行,或者那个函数有问题
你页面用的是addCateForm,页面创建的时候调用的是getcateList方法,根本没给addCateForm赋值啊
您好,我是有问必答小助手,你的问题已经有小伙伴为您解答了问题,您看下是否解决了您的问题,可以追评进行沟通哦~
如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~
ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632
非常感谢您使用有问必答服务,为了后续更快速的帮您解决问题,现诚邀您参与有问必答体验反馈。您的建议将会运用到我们的产品优化中,希望能得到您的支持与协助!
速戳参与调研>>>https://t.csdnimg.cn/Kf0y