zoukankan      html  css  js  c++  java
  • 简述逻辑外键

    goods表创建逻辑外键

    前端数据我需要做二次处理,获取表单数据进行二次处理,转成json数据,这样后端接收存入数据库。

    之后在添加方法中获取id 向后端发起请求

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34

    // 添加商品事件
    submit:function(){
    // 非空验证
    if (this.name == ''){
    this.$Message("商品名称不能为空")
    }else{
    // 存入字段为json
    var param = {};
    param['color'] = this.color
    param['size'] = this.size
    param['season'] = this.season
    //转为json数据
    param=JSON.stringify(param)
    // 接收表单数据
    var pc = this.$refs.upload
    let file = pc.files[0]
    var data = new FormData()
    data.append('img',file)
    data.append('flows',this.flows)
    // 反向赋值
    data.append('cid',this.cate[this.selected])
    // 声明请求头
    let config={
    'Content-Type':'multipart/form-data'
    }
    // 发起请求
    this.axios.post('http://127.0.0.1:8000/addgoods/',data,config).then((res=>{
    console.log(res)
    this.$Message(res.data.msg)
    }))

    }
    }

    把json数据存入规格字段中,cid存入外键的cid

    之后,我们展示分类

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    // 定义规格名称
    color:'',
    size:'',
    season:'',
    // 分类表默认选中
    selected:'衣服',
    cate:[],
    // 接受商品分类
    category:[]

    // 创建方法

    // 获取商品分类
    get_cate:function(){
    //发送请求
    this.axios.get('http://127.0.0.1:8000/cate/').then((res=>{
    console.log(res)
    // 二次处理数据
    var mycate=[]
    for(let i=0;i<res.data.length;i++){
    mycate.push(res.data[i]['name'])
    // 反向赋值 将分类表的id存入goods表中
    this.cate[res.data[i]['name']] = res.data[i]['id'];
    }
    // 赋值
    this.category = mycate
    }))
    },
  • 相关阅读:
    bzoj3159: 决战
    Codeforces Round #516 (Div. 1, by Moscow Team Olympiad) C
    Codeforces Round #516 (Div. 1, by Moscow Team Olympiad) B
    Codeforces Round #516 (Div. 1, by Moscow Team Olympiad) A
    loj 6401 字符串
    BZOJ5194 雪地靴
    BZOJ 4709 柠檬
    BZOJ 3343 魔法
    [8月16日绍兴]试剂
    设备塔
  • 原文地址:https://www.cnblogs.com/anle123/p/13365478.html
Copyright © 2011-2022 走看看