最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

iview實(shí)現(xiàn)圖片上傳功能

 更新時(shí)間:2020年06月29日 10:22:58   作者:沫熙瑾年  
這篇文章主要為大家詳細(xì)介紹了iview實(shí)現(xiàn)圖片上傳功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了iview實(shí)現(xiàn)圖片上傳的具體代碼,供大家參考,具體內(nèi)容如下

如下圖片:這里結(jié)合iview里面表單驗(yàn)證做的

完整代碼如何 

<template>
 <div>
  <div class="navigation">
   <p>
   <span>管理首頁(yè)&nbsp;>&nbsp;應(yīng)用&nbsp;>&nbsp;搶單俠>&nbsp;信貸管理>&nbsp;{{title}}</span>
   </p>
  </div>
  <div class="clearfix contentcss sales-statis">
   <Form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="80">
    <FormItem label="模板名稱:" prop="templatename">
     <Input v-model="formValidate.templatename" placeholder="請(qǐng)輸入模板名稱" style="width:240px"></Input>
    </FormItem>
    <FormItem label="模板類別:" prop="templatetype">
     <Select v-model="formValidate.templatetype" placeholder="請(qǐng)選擇模板類別" style='width:240px;'>
      <Option v-for="item in templateList" :value="item.templateCode" :key="item.templateCode">{{ item.templateName }}</Option>
     </Select>
    </FormItem>
    
    <FormItem label="開放范圍:" prop="openrange">
     <Select v-model="formValidate.openrange" placeholder="請(qǐng)選擇開放范圍" style='width:240px;'>
      <Option v-for="item in openrangeList" :value="item.openrangeCode" :key="item.openrangeCode">{{ item.openrangeName }}</Option>
     </Select>
    </FormItem>
    <FormItem label="上傳圖片:" prop="productlogo">
     <Upload
     action=""
     :before-upload="handleUploadicon"
     :show-upload-list="false"
     :format="['jpg','jpeg','png', 'gif']"
     :on-format-error="handleFormatError1">
     <img class="iconlabelUrl" :src="formValidate.labelUrl" alt="">
     <Input v-model="formValidate.productlogo" disabled style="width: 120px;margin-top:24px" class="left ml5 hidden"></Input>
     <!-- <Button type="ghost" icon="ios-cloud-upload-outline">上傳文件</Button> -->
     </Upload>
    </FormItem>
    <FormItem>
     <Button type="primary" @click="handleSubmit('formValidate')" style='width:100px'>保存</Button>
     <Button @click="handleReset('formValidate')" style="margin-left: 8px;width:100px">返回</Button>
    </FormItem>
   </Form>
  </div>
 </div>
</template>
<script>
 export default{
  data(){
   return{
    title:'',
    openrangeList:[
     {openrangeCode:'1',openrangeName:'全部用戶'},
     {openrangeCode:'2',openrangeName:'會(huì)員用戶'},
    ],
    templateList:[
     {templateCode:'1',templateName:'海報(bào)'},
     {templateCode:'2',templateName:'名片'}
    ],
    formValidate: {
     productlogo:'',
     templatename:'',
     templatetype:'1',
     openrange:'1',
     labelUrl: require("../../image/moren.png")
 
    },
    ruleValidate:{
      templatename:[
      {required: true, message: '請(qǐng)輸入模板名稱', trigger: 'change'},
     ],
     productlogo:[
      { required: true, message: "請(qǐng)上傳圖片", trigger: "blur" }
     ]
    }
   }
  },
  methods:{
   handleUploadicon(file) {
    let splic = file.name.split(".");
    if (
     splic[splic.length - 1] == "png" ||
     splic[splic.length - 1] == "jpg" ||
     splic[splic.length - 1] == "gif" ||
     splic[splic.length - 1] == "jpeg"
    ) {
     let formData = new FormData();
     formData.append("file", file);
     let config = {
     headers: {
      "Content-Type": "multipart/form-data"
     }
     };
     this.http
     .post(BASE_URL + "/fileUpload", formData, config)
     .then(resp => {
      if (resp.code == "success") {
      this.formValidate.labelUrl = resp.data;
      this.formValidate.productlogo = resp.data;
      } else {
      }
     })
     .catch(() => {});
     return false;
    }
   },
   handleFormatError1(file) {
   this.$Message.info("圖片格式不正確,請(qǐng)上傳正確的圖片格式");
   },
   handleSubmit (name) {
    this.$refs[name].validate((valid) => {
     if (valid) {
      if(this.title = '添加模板'){
       this.$Modal.confirm({
        title: "溫馨提示",
        content: "<p>確認(rèn)添加該模板?</p>",
        onOk: () => {
         let data = {
          exhibitionName : this.formValidate.templatename,
          exhibitionType : this.formValidate.templatetype,
          openType : this.formValidate.openrange,
          exhibitionPath : this.formValidate.productlogo
         }
         this.http.post(BASE_URL+'后臺(tái)保存接口',data)
         .then(data=>{
          if(data.code=='success'){
           this.$Message.success('添加成功');
           this.$router.push('/exhibition')
          }else{
           this.$Message.error('添加失敗')
          }
         }).catch(err=>{
          console.log(err)
         })
        },
        onCancel: () => {}
       });
      }else{
       this.$Modal.confirm({
        title: "溫馨提示",
        content: "<p>確認(rèn)修改該模板?</p>",
        onOk: () => {
         let data = {
          exhibitionName : this.formValidate.templatename,
          exhibitionType : this.formValidate.templatetype,
          openType : this.formValidate.openrange,
          exhibitionPath : this.formValidate.productlogo
         }
         this.http.posst(BASE_URL+'后臺(tái)修改接口',data)
         .then(data=>{
          if(data.data=='success'){
           this.$Message.success('修改成功');
           this.$router.push('/exhibition')
          }else{
           this.$Message.error('修改失敗')
          }
         }).catch(err=>{
          console.log(err)
         })
        },
        onCancel: () => {}
       });
      }
     } 
    })
   },
   handleReset(name){
    this.$refs[name].resetFields()
    this.$router.push('/exhibition')
   }
  },
  mounted(){
   if(this.$route.query.id){
    this.title = '添加模板'
   }else{
    this.title = '編輯模板'
    let data = {
     exhibitionCode:this.$route.query.exhibitionCode
    }
    this.http.post(BASE_URL+'/loan/exhibition/getByCode',data)
    .then(data=>{
     if(data.code=='success'){
      this.formValidate.templatename=data.data.exhibitionName,
      this.formValidate.templatetype=data.data.exhibitionType,
      this.formValidate.openrange=data.data.openType,
      this.formValidate.labelUrl= data.data.exhibitionPath,
      this.formValidate.productlogo=data.data.exhibitionPath
     }
    })
   }
  }
 }
</script>
<style lang="less" scoped>
 .title{
  height:60px;line-height:60px;background:#fff;
  font-size: 20px;text-indent: 20px;
 }
 .ivu-form .ivu-form-item-label{
  text-align: justify !important
 }
 .iconlabelUrl {
  width: 240px;
  height: 120px;
 }
</style>

關(guān)于vue.js組件的教程,請(qǐng)大家點(diǎn)擊專題vue.js組件學(xué)習(xí)教程進(jìn)行學(xué)習(xí)。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Vue開發(fā)實(shí)例探究key的作用詳解

    Vue開發(fā)實(shí)例探究key的作用詳解

    這篇文章主要為大家介紹了Vue開發(fā)實(shí)例探究key的作用詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-01-01
  • 一起來學(xué)習(xí)Vue的組件間通信方式

    一起來學(xué)習(xí)Vue的組件間通信方式

    這篇文章主要為大家詳細(xì)介紹了Vue的組件間通信方式,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助
    2022-03-03
  • vue購(gòu)物車插件編寫代碼

    vue購(gòu)物車插件編寫代碼

    這篇文章主要為大家詳細(xì)介紹了vue購(gòu)物車插件的編寫代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-11-11
  • 詳解vue頁(yè)面首次加載緩慢原因及解決方案

    詳解vue頁(yè)面首次加載緩慢原因及解決方案

    這篇文章主要介紹了詳解vue頁(yè)面首次加載緩慢原因及解決方案,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-11-11
  • vxe-table中vxe-grid(高級(jí)表格)的使用方法舉例

    vxe-table中vxe-grid(高級(jí)表格)的使用方法舉例

    vxe-table是一個(gè)基于vue的表格組件,下面這篇文章主要給大家介紹了關(guān)于vxe-table中vxe-grid(高級(jí)表格)的使用方法,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2024-05-05
  • 講解vue-router之什么是嵌套路由

    講解vue-router之什么是嵌套路由

    這篇文章主要介紹了講解vue-router之什么是嵌套路由,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-05-05
  • 使用Vue Composition API寫出清晰、可擴(kuò)展的表單實(shí)現(xiàn)

    使用Vue Composition API寫出清晰、可擴(kuò)展的表單實(shí)現(xiàn)

    這篇文章主要介紹了使用Vue Composition API寫出清晰、可擴(kuò)展的表單實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-06-06
  • Vant Weapp組件踩坑:picker的初始賦值解決

    Vant Weapp組件踩坑:picker的初始賦值解決

    這篇文章主要介紹了Vant Weapp組件踩坑:picker的初始賦值解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2020-11-11
  • 詳解Vue路由鉤子及應(yīng)用場(chǎng)景(小結(jié))

    詳解Vue路由鉤子及應(yīng)用場(chǎng)景(小結(jié))

    本篇文章主要介紹了詳解Vue路由鉤子及應(yīng)用場(chǎng)景(小結(jié)),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-11-11
  • vue3基于script?setup語法$refs的使用

    vue3基于script?setup語法$refs的使用

    這篇文章主要介紹了vue3基于script?setup語法$refs的使用,<BR>?在用vue3開發(fā)項(xiàng)目的時(shí)候,需要調(diào)用子組件的方法,于是想著用$refs來實(shí)現(xiàn),但是我是使用script?setup語法糖,原先vue2的語法已經(jīng)不適用了。下面我們一起進(jìn)入文章看詳細(xì)內(nèi)容吧</P><P>
    2021-12-12

最新評(píng)論

密云县| 八宿县| 武功县| 竹山县| 安泽县| 罗江县| 克拉玛依市| 民县| 巩留县| 枣阳市| 五指山市| 莎车县| 墨江| 东阳市| 渭源县| 平乡县| 兖州市| 长沙市| 邵阳县| 衡东县| 醴陵市| 同江市| 温宿县| 仁化县| 包头市| 江达县| 安阳市| 绍兴市| 尚志市| 乐至县| 长岛县| 桑日县| 嫩江县| 大悟县| 贡山| 泰和县| 台中县| 九寨沟县| 长葛市| 祁东县| 车险|