日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > vue >内容正文

vue

关于vue项目中在js中引入图片问题

發布時間:2025/5/22 vue 156 豆豆
生活随笔 收集整理的這篇文章主要介紹了 关于vue项目中在js中引入图片问题 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

<template>
<div>
<img v-for="(star,index) in stars" :src="star.src" @click="rating(index)" alt="星星圖片"/>
</div>
</template>

<script>
//星星的圖片路徑
// var starOffImg = "../../../static/images/OrderCenter/pinglun/wmwjx.png";
// var starOnImg = "../../../static/images/OrderCenter/pinglun/mwjx.png";

import starOffImg from '../../../static/images/OrderCenter/pinglun/wmwjx.png'; // import 引入圖片
import starOnImg from '../../../static/images/OrderCenter/pinglun/mwjx.png'; // import 引入圖片

export default {
data() {
return {
stars: [
{
src: starOffImg,
active: false
},
{
src: starOffImg,
active: false
},
{
src: starOffImg,
active: false
},
{
src: starOffImg,
active: false
},
{
src: starOffImg,
active: false
}
],
};
},
methods: {
//評分
rating: function (index) {
var total = this.stars.length; //星星總數
var idx = index + 1; //這代表選的第idx顆星-也代表應該顯示的星星數量

//如果再次點擊當前選中的星級-僅取消掉當前星級,保留之前的。
if (idx == this.starNum) {
for (var i = index; i < total; i++) {
this.stars[i].src = starOffImg;
this.stars[i].active = false;
}
}
//如果小于當前最高星級,則直接保留當前星級
if (idx < this.starNum) {
for (var i = idx; i < this.starNum; i++) {
this.stars[i].src = starOffImg;
this.stars[i].active = false;
}
}
//如果大于當前星級,則直接選到該星級
if (idx > this.starNum) {
for (var i = 0; i < idx; i++) {
this.stars[i].src = starOnImg;
this.stars[i].active = true;
}
}

var count = 0; //計數器-統計當前有幾顆星
for (var i = 0; i < total; i++) {
if (this.stars[i].active) {
count++;
}
}
this.starNum = count;
}
},


}
</script>

<style scoped>

img{
width: 34px;
height: 32px;
margin-left: 32px;
}
</style>

轉載于:https://www.cnblogs.com/WangXinPeng/p/9413530.html

總結

以上是生活随笔為你收集整理的关于vue项目中在js中引入图片问题的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。