vue实现文件上传样式修改

 主代码:

<div class="wxchatIcon1" >

                <input  ref="uploadImage" accept="image/*" style="display: none" type="file" id="file"  @change="handleUploadSuccess"/>

                <i @click="choiceImg" style="fontSize:'18px',fontWeight:'bold',padding:10px" class="el-icon-picture" ></i>

            </div>

style 

.wxchatIcon1 {
  display: inline-block;
    padding: 8px 10px 0px 30px;
    width: 40px;
    font-size: 20px;
  }

js

 //图片发送
    choiceImg(){
      this.$refs.uploadImage.click();
    },
    handleUploadSuccess() {
      var thit = this;
      const input = thit.$refs.uploadImage;
      const file = input.files[0];
      // let dialogImageUrl = this.dataObj.host + '/' + this.dataObj.key.replace('${filename}', file.name);
      let reader = new FileReader();
      reader.readAsArrayBuffer(file);
      reader.onload = function (e) {
          let res = e.target.result;//ArrayBuffer
          let buf = Buffer.from(res);//Buffer
          var Minio = require('minio')
          var minioClient = new Minio.Client({
            endPoint: '127.0.0.1',
            port: 19000,
            useSSL: false,
            accessKey: 'admin',
            secretKey: '123456'
          });
      minioClient.putObject('chat', file.name, buf, null, file.size, function (err, data) {
          if (err)
              console.log(err)
          else
          var msgimg = {"type":"send","send_id":thit.uid,"receive_id":thit.chooseId,"msg_type":"4","content":"http://113.156.111.000:19000/chat/"+file.name};
          if (thit.$webSocket.ws && thit.$webSocket.ws.readyState == 1) {
            thit.$webSocket.ws.send(JSON.stringify(msgimg));
          }
          setTimeout(() => {
            thit.getChatList();
          }, 300)
      });
      }

    },

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,下面是一个简单的使用Vue实现Telegram文件发送样式的示例: ```html <template> <div class="file-upload"> <div class="file-select"> <span class="file-select-button" @click="$refs.fileInput.click()">Choose File</span> <div class="file-select-name">{{ fileName }}</div> <input type="file" ref="fileInput" @change="onFileChange"> </div> <button class="file-upload-button" @click.prevent="uploadFile">Send</button> </div> </template> <script> export default { data() { return { file: null, fileName: 'No file selected' } }, methods: { onFileChange(event) { this.file = event.target.files[0] this.fileName = this.file ? this.file.name : 'No file selected' }, uploadFile() { // Upload file to server } } } </script> <style scoped> .file-upload { display: flex; align-items: center; justify-content: space-between; padding: 10px; border: 1px solid #ccc; border-radius: 5px; } .file-select { display: flex; align-items: center; flex: 1; } .file-select-button { font-size: 14px; padding: 5px 10px; color: #fff; background-color: #0088cc; border-radius: 5px; cursor: pointer; } .file-select-name { margin-left: 10px; font-size: 14px; color: #555; } .file-upload-button { margin-left: 10px; font-size: 14px; padding: 5px 10px; color: #fff; background-color: #0088cc; border: none; border-radius: 5px; cursor: pointer; } .file-upload-button:hover { background-color: #006699; } </style> ``` 在上面的代码,我们定义了一个包含文件上传功能的组件,使用Vue的`v-model`指令将文件上传框的值绑定到组件的数据属性,监听`@change`事件获取上传的文件,使用CSS样式美化文件上传框和发送按钮。当用户点击发送按钮时,调用`uploadFile`方法来上传文件,可以在该方法将文件发送到服务器。 最后,您需要将组件导出并在父组件使用它。例如: ```html <template> <div> <file-upload></file-upload> </div> </template> <script> import FileUpload from './FileUpload.vue' export default { components: { FileUpload } } </script> ``` 以上是一个简单的使用Vue实现Telegram文件发送样式的示例。您可以根据自己的需求进行修改和扩展。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值