• 关于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{
    34px;
    height: 32px;
    margin-left: 32px;
    }
    </style>

  • 相关阅读:
    maven打包时跳过测试
    idea打包SpringBoot项目打包成jar包和war
    idea下springboot打包成jar包和war包,并且可以在外部tomcat下运行访问到
    idea16使用maven命令clean、编译、打包jar或者war
    关于spring boot jar包与war包的问题
    spring boot-html和templates
    spring boot之访问静态页面
    奇虎360选择IPO “壳概念”很受伤
    不怕成本高,不怕卖的少。高端形象一定要打起来。
    ddddd
  • 原文地址:https://www.cnblogs.com/WangXinPeng/p/9413530.html
Copyright © 2020-2023  润新知