vue页面基本增删改查

练手项目vue页面

新手前端轻喷:
效果如下
在这里插入图片描述
1、2两个部分组成:
对应代码中 element-ui中的 el-form 和 el-table

照着抄呗,硬着头皮来!
建议:认真读一遍你用的组件

在这里插入图片描述
那上边简单得列表举例:
建议大家手敲一个最简单的:

可能出现的坑点

1、js语句没有写道script标签内。
2、自定义方法没有写道method:{}中
3、在funtion(){}中调用this方法 和在()=>{}中调用this的this不是一个对象,
4、标签拼错了 比如 prop敲成porp

在这里插入图片描述

<template>
  <div class="app-container">
    <!-- <el-form size="small" :inline="true" label-width="100px">

  </el-form> -->
    <el-table style="width: 100%;" :data="lunboList">
      <el-table-column label="序号" type="index" align="center">
      </el-table-column>
      <el-table-column label="轮播图id" align="center" prop="imageId" />
      <el-table-column 
        label="图片" 
        align="center" 
        prop="imageUrl" 
        :show-overflow-tooltip="true">
        <template slot-scope="{row}">
            <el-image :src="row.imageUrl" style="width: 160px; height: 90px;"></el-image>
        </template>
      </el-table-column>
      <el-image :src="imageUrl"></el-image>
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="状态" align="center" prop="status" key="status" >
        <template slot-scope="scope">
          <el-switch
            v-model="scope.row.status"
            :active-value=1
            :inactive-value=0
            @change="handleStatusChange(scope.row)"
          ></el-switch>
        </template>
      </el-table-column>
    </el-table>
  </div>

</template>

上边的问题3:[最早的代码是then(function(){}) 但这是不对的]
在这里插入图片描述

<script>
  import {getLunbolist,updateLuobo} from '@/api/school/common'
  export default {
    name: "",
    data() {
      return {
        lunboList: [
        {
          imageUrl:"",
          remark:"",
          status: 0
        }
        ],
      }
    },
    created() {
      this.getLunboList();
    },
    methods:{
         // 用户状态修改
    handleStatusChange(row) {
      console.log("修改后row传入数据",row)
      let imageId = row.imageId;
      let text = row.status === "1" ? "启用" : "停用";
      this.$modal.confirm('确认要"' + text + '""' + row.imageId + '"记录吗?').then(()=> {
        return this.changeLunboStatus(row.imageId, row.status);
      }).catch((error)=>{
        console.log("出现错误",error)
      }

      )
      
      .then(() => {
        this.$modal.msgSuccess(text + "成功");
      }).catch(function() {
        row.status = row.status === "0" ? "1" : "0";
      });
    },
   // 获取lunbo列表
   getLunboList() {
      console.log("qqqqqqqqqqqqqqqqqqqqqqqq")
      getLunbolist().then(res=>{
        console.log(res);
        this.lunboList = res.rows;
      })
    },
    changeLunboStatus(imageId,status){
      console.log("修改轮播status",imageId,status)
       let data ={
         imageId:imageId,
         status:status
       }
       console.log("修改轮播status组装数据data",data)
       updateLuobo(data).then(res=>{
          this.getLunboList()
      })
    }
    },
  };
</script>

<style scope>
</style>
  • 7
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值