上传图片
- 用到u-upload组件的@afterRead和@delete事件,前者用push方法添加图片路径,后者用splice(第一个参数重哪个位置开始,第二个参数删除几个元素)删除
<template>
<view>
<u-upload :fileList="fileList" @afterRead="readImg" :deletable="true" @delete="delImg"></u-upload>
</view>
</template>
<script>
export default {
data() {
return {
fileList: []
}
},
methods: {
readImg(e) {
console.log(e)
this.fileList.push({url: e.file.url})
},
delImg(e) {
console.log(e)
this.fileList.splice(e.index,1)
}
}
}
</script>
数组方法Jion
- 使用数组方法array.jion(),如果括号里面不传,默认使用逗号分隔
<template>
<view>
<view class="">{{strFalinl}}</view>
</view>
</template>
<script>
export default {
data() {
return {
strList: ['第一个字符','第二个字符串','第三个字符串'],
strFalinl: ''
}
},
mounted() {
this.str()
},
methods: {
str() {
var list = []
this.strList.forEach(item=> {
console.log(item)
list.push(item)
})
console.log(list)
this.strFalinl = list.join()
}
}
}
</script>