Vue 触发视图更新数组方法
Vue 将被侦听的数组的变更方法进行了包裹,所以它们也将会触发视图更新。这些被包裹过的方法包括:
- push()
- pop()
- shift()
- unshift()
- splice()
- sort()
- reverse()
实现鼠标copy功能
https://www.cnblogs.com/wyhlightstar/p/8950430.html
1、 首先需要安装依赖 * 出现错误的话,可以试试 cnpm
npm install --save vue-clipboard2
2、 安装成功之后就可以开始使用了
对于vue-cli
import Vue from 'vue'
import VueClipboard from 'vue-clipboard2'
Vue.use(VueClipboard)
对于常规的用法
<script src="vue.min.js"></script>
<!-- 必须在vue.js之后放置这一行 -->
<script src="vue-clipboard.min.js"></script>
3、 Dome的使用:
复制代码
<template>
<div class="wxsmallcode-page publicCon">
<div class="copyBox">
sysAppId:<span>{{sysAppIds}}</span>
<el-button class="ml10" type="text" size="medium"
v-clipboard:copy="sysAppIds"
v-clipboard:success="onCopy"
v-clipboard:error="onError">点击复制</el-button>
</div>
</template>
复制代码
复制代码
<script>
export default {
data(){
return {
sysAppIds: 'xxxxxxxxxxxsx'
}
},
methods: {
// 复制成功
onCopy(e){
console.log(e);
},
// 复制失败
onError(e){
alert("失败");
},
}
}
</script>
复制代码
路由相关
路由传值
- url上不暴露值得方式传值
this.$router.push({name:'taskCenter', params:{id: 123, savePath: 123}})
//获取
$route: {
handler(route) {
console.log('route',route)
const {id,savePath} = route.params
}
},
'/home/huan?uid=1¶m=2'
const {uid,param} =this.$route.query
'/home/huan/1/2'
待完成
csv文件上传
链接:
https://blog.csdn.net/weixin_44481476/article/details/108296932
https://blog.csdn.net/qq_36597079/article/details/86612667
等等,好多链接都一样内容
。。。。
<el-upload
ref="upload"
class="upload-demo"
drag
action
:multiple="false"
:limit="1"
:auto-upload="false"
>
<!-- :on-change="handleFileChange" -->
<i class="el-icon-upload"></i>
<div class="el-upload__text">将文件拖到此处,或<em>选择文件</em></div>
<div slot="tip" class="el-upload__tip">只能上传.csv文件</div>
</el-upload>
<el-button size="small" type="primary" style="margin-left: 10px;" @click="handleFileChange()">上传</el-button>
<script>
export default {
data(){
return {
sysAppIds: 'xxxxxxxxxxxsx'
}
},
methods: {
/**
* 上传
*/
async handleFileChange(uploadType) {
// console.log('file',file)
const file = this.$refs.upload.uploadFiles[0]
this.fileTemp = file.raw;
if (this.fileTemp) {
if (
this.fileTemp.type == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' ||
this.fileTemp.type == 'application/vnd.ms-excel'
) {
await this.importfxx(this.fileTemp,uploadType);
await this.$refs.upload.clearFiles()
} else {
this.$message({
type: 'warning',
message: '附件格式错误,请删除后重新上传!'
});
}
} else {
this.$message({
type: 'warning',
message: '请上传附件!'
});
}
},
importfxx(obj,uploadType) {
let _this = this;
let inputDOM = this.$refs.inputer; // 通过DOM取文件数据
// this.file = event.currentTarget.files[0];
this.file = obj;
// console.log('this.file',this.file)
let rABS = false; //是否将文件读取为二进制字符串
let f = this.file;
let reader = new FileReader(); //if (!FileReader.prototype.readAsBinaryString) {
FileReader.prototype.readAsBinaryString = function(f) {
let binary = '';
let rABS = false; //是否将文件读取为二进制字符串
let pt = this;
let wb; //读取完成的数据
let outdata;
let isCSV = true;
let reader = new FileReader();
reader.onload = function(e) {
let data = e.target.result;
let XLSX = require('xlsx');
wb = null;
if (isCSV) {
data = new Uint8Array(data);
let f = _this.isUTF8(data);
//console.log("是CSV文件,编码" + (f ? "是" : "不是") + "UTF-8");
if (f) {
data = e.target.result;
} else {
let str = cptable.utils.decode(936, data);
wb = XLSX.read(str, {
type: 'string'
});
}
} else {
//console.log("不是CSV文件");
}
if (!wb) {
wb =
rABS || isCSV
? XLSX.read(btoa(_this.fixdata(data)), {
type: 'base64'
})
: XLSX.read(data, {
type: 'binary'
});
}
outdata = XLSX.utils.sheet_to_json(wb.Sheets[wb.SheetNames[0]]); //outdata就是你想要的东西
console.log('未处理的原始数据如下:');
console.log(outdata); //此处可对数据进行处
};
reader.readAsArrayBuffer(f);
};
if (rABS) {
reader.readAsArrayBuffer(f);
} else {
reader.readAsBinaryString(f);
}
},
isUTF8(bytes) {
//非中文格式CSV文件转换UTF-8方法
var i = 0;
while (i < bytes.length) {
if (
// ASCII
bytes[i] == 0x09 ||
bytes[i] == 0x0a ||
bytes[i] == 0x0d ||
(0x20 <= bytes[i] && bytes[i] <= 0x7e)
) {
i += 1;
continue;
}
if (
// non-overlong 2-byte
0xc2 <= bytes[i] &&
bytes[i] <= 0xdf &&
0x80 <= bytes[i + 1] &&
bytes[i + 1] <= 0xbf
) {
i += 2;
continue;
}
if (
// excluding overlongs
(bytes[i] == 0xe0 && 0xa0 <= bytes[i + 1] && bytes[i + 1] <= 0xbf && 0x80 <= bytes[i + 2] && bytes[i + 2] <= 0xbf) || // straight 3-byte
(((0xe1 <= bytes[i] && bytes[i] <= 0xec) || bytes[i] == 0xee || bytes[i] == 0xef) &&
0x80 <= bytes[i + 1] &&
bytes[i + 1] <= 0xbf &&
0x80 <= bytes[i + 2] &&
bytes[i + 2] <= 0xbf) || // excluding surrogates
(bytes[i] == 0xed && 0x80 <= bytes[i + 1] && bytes[i + 1] <= 0x9f && 0x80 <= bytes[i + 2] && bytes[i + 2] <= 0xbf)
) {
i += 3;
continue;
}
if (
// planes 1-3
(bytes[i] == 0xf0 &&
0x90 <= bytes[i + 1] &&
bytes[i + 1] <= 0xbf &&
0x80 <= bytes[i + 2] &&
bytes[i + 2] <= 0xbf &&
0x80 <= bytes[i + 3] &&
bytes[i + 3] <= 0xbf) || // planes 4-15
(0xf1 <= bytes[i] &&
bytes[i] <= 0xf3 &&
0x80 <= bytes[i + 1] &&
bytes[i + 1] <= 0xbf &&
0x80 <= bytes[i + 2] &&
bytes[i + 2] <= 0xbf &&
0x80 <= bytes[i + 3] &&
bytes[i + 3] <= 0xbf) || // plane 16
(bytes[i] == 0xf4 &&
0x80 <= bytes[i + 1] &&
bytes[i + 1] <= 0x8f &&
0x80 <= bytes[i + 2] &&
bytes[i + 2] <= 0xbf &&
0x80 <= bytes[i + 3] &&
bytes[i + 3] <= 0xbf)
) {
i += 4;
continue;
}
return false;
}
return true;
},
fixdata(data) {
//文件流转BinaryString
let o = '',
l = 0,
w = 10240;
for (; l < data.byteLength / w; ++l) o += String.fromCharCode.apply(null, new Uint8Array(data.slice(l * w, l * w + w)));
o += String.fromCharCode.apply(null, new Uint8Array(data.slice(l * w)));
return o;
},
}
}
</script>