vue+Element?ui實(shí)現(xiàn)照片墻效果
本文實(shí)例為大家分享了vue+Element ui實(shí)現(xiàn)照片墻效果的具體代碼,供大家參考,具體內(nèi)容如下

上面是我要實(shí)現(xiàn)的效果。直接上代碼,簡潔明了
1.前端視圖代碼
<div> ? <el-upload ? ? :file-list="fileList" ? ? :headers="upload.headers" ? ? :action="upload.url" ? ? list-type="picture-card" ? ? :on-preview="handlePictureCardPreview" ? ? :on-remove="handleRemove"> ? ? <i class="el-icon-plus"></i> ? </el-upload> ? <el-dialog :visible.sync="dialogVisible"> ? ? <img width="100%" height="500px" :src="dialogImageUrl" alt=""> ? </el-dialog> </div>
2.前端script部分代碼
<script>
import { listNetSecurityImg, delNetSecurityImg } from '@/api/websitemanage/netsecurityimg'
import { getToken } from '@/utils/auth'
export default {
? name: 'NetSecurityImg',
? components: {},
? data() {
? ? return {
? ? ? titleName: '圖片管理',
? ? ? form: {},
? ? ? dialogImageUrl: '',
? ? ? dialogVisible: false,
? ? ? fileList: [],
? ? ? // 照片墻
? ? ? upload: {
? ? ? ? // 設(shè)置上傳的請求頭部
? ? ? ? headers: { token: getToken() },
? ? ? ? // 上傳的地址
? ? ? ? url: process.env.VUE_APP_BASE_API + 'netSecurityImg/importNetSecurityImg'
? ? ? }
? ? }
? },
? created() {
? ? this.getList()
? },
? methods: {
? ? /** 網(wǎng)安時(shí)情圖片列表 */
? ? getList() {
? ? ? this.fileList = []
? ? ? listNetSecurityImg().then(response => {
? ? ? ? const imgList = response.data
? ? ? ? for (let i = 0; i < imgList.length; i++) {
? ? ? ? ? this.fileList.push({
? ? ? ? ? ? 'uid': imgList[i].id,
? ? ? ? ? ? 'url': imgList[i].imgUrl
? ? ? ? ? })
? ? ? ? }
? ? ? })
? ? },
? ? handleRemove(file, fileList) {
? ? ? const id = file.uid
? ? ? this.$confirm('是否確認(rèn)刪除此圖片?', '警告', {
? ? ? ? confirmButtonText: '確定',
? ? ? ? cancelButtonText: '取消',
? ? ? ? type: 'warning'
? ? ? }).then(function() {
? ? ? ? return delNetSecurityImg(id)
? ? ? }).then(response => {
? ? ? ? if (response.success) {
? ? ? ? ? this.getList()
? ? ? ? ? this.msgSuccess('刪除成功')
? ? ? ? }
? ? ? }).catch(() => {
? ? ? ? this.getList()
? ? ? })
? ? },
? ? handlePictureCardPreview(file) {
? ? ? this.dialogImageUrl = file.url
? ? ? this.dialogVisible = true
? ? }
? }
}
</script>3.api接口js
import request from '@/utils/request'
// 查詢圖片列表
export function listNetSecurityImg(query) {
? return request({
? ? url: 'netSecurityImg/getList',
? ? method: 'post',
? ? data: query
? })
}
// 刪除圖片
export function delNetSecurityImg(id) {
? return request({
? ? url: 'netSecurityImg/delete?id=' + id,
? ? method: 'post'
? })
}4.表的設(shè)計(jì)

注意,后臺(tái)接口上傳圖片文件是上傳到文件服務(wù)器的,文件服務(wù)器返回的圖片url進(jìn)入到數(shù)據(jù)庫
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
vue實(shí)現(xiàn)導(dǎo)出word文檔的示例代碼
這篇文章主要為大家詳細(xì)介紹了如何使用vue實(shí)現(xiàn)導(dǎo)出word文檔(包括圖片),文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2024-01-01
vue css 引入asstes中的圖片無法顯示的四種解決方法
這篇文章主要介紹了vue css 引入asstes中的圖片 無法顯示的幾種解決方案,本文給出了四種解決方法,每種方法給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-03-03
用element的upload組件實(shí)現(xiàn)多圖片上傳和壓縮的示例代碼
這篇文章主要介紹了用element的upload組件實(shí)現(xiàn)多圖片上傳和壓縮的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-02-02
element-ui中實(shí)現(xiàn)tree子節(jié)點(diǎn)部分選中時(shí)父節(jié)點(diǎn)也選中
這篇文章主要介紹了element-ui中實(shí)現(xiàn)tree子節(jié)點(diǎn)部分選中時(shí)父節(jié)點(diǎn)也選中的方式,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-08-08
vue項(xiàng)目兩種方式實(shí)現(xiàn)豎向表格的思路分析
這篇文章主要介紹了vue項(xiàng)目兩種方式實(shí)現(xiàn)豎向表格的思路分析,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-04-04
vue大文件分片上傳之simple-uploader.js的使用
本文主要介紹了vue大文件分片上傳之simple-uploader.js的使用,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-05-05
vue中使用 pinia 全局狀態(tài)管理的實(shí)現(xiàn)
本文主要介紹了vue中使用 pinia 全局狀態(tài)管理的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-07-07

