vue 选项卡切换,数据不响应。为啥了?

发布于 2022-09-06 19:47:28 字数 2785 浏览 22 评论 0

代码如下,我的选项卡是,根据一个总分来渲染每一个分数。 每个分数对应相同的知识点,用户可以在相应的分数下高亮知识点。

每个分数选项卡切换和高亮是独立的。

为什么,3个分数按钮,,切换 不管用呢?

clipboard.png

全部代码

<template>
    <div >
          <p style="margin-top:10px;">
            分数:
            <template v-for="n in score">
              <el-button  size="small"  v-html="n" :data-item ="JSON.stringify(item)"  @click="setKnowLedge(item,$event)"></el-button>
            </template>
          </p>
          <p style="margin-top:10px;">
         知识点:
            <span v-for="i in item.basetree" :key="i.basecodeVo+Math.random()">
              <el-button 
                v-for="j in i.sons"
                :key="j.idVo+Math.random()"
                :class="{checked:j.isRight}"
                class="buttonstyle"
                @click="treeChange(item,j,$event)">{{j.nameVo}}
              </el-button>
            </span>
        </p>
    </div>
</template>
<script type="text/javascript">
  import {strToUrl} from '../../main'
  export default {
    data (){
      return {
      }
    },
    props: ['item','score'],
    mounted: function () {
//      this.paperDetail();
    },
    watch:{
      code:'paperDetail'
    },
    methods: {
      treeChange(item,j,$event) {
          j.isRight = +(!j.isRight);
          j.isTrue = j.isRight;

          var dataItem = JSON.stringify(item);

         this.$nextTick(function(){

          console.log($($event.target));
            //console.log($($event.target).closest('.scoreBox'))
            $($event.target).closest('.scoreBox').find('.active').get(0).setAttribute('data-item',dataItem);
         })
      },
      setKnowLedge(item,$event){
        console.log($event.target)
         var dataItem = JSON.parse($event.target.getAttribute('data-item'));

         dataItem.active = true;

         Object.assign(item,JSON.parse(JSON.stringify(dataItem)));


         this.$nextTick(function(){
           console.log($event.target)
           //console.log(dataItem,22222)
           $($event.target).siblings().removeClass('active')
           $($event.target).addClass('active')          
         })
      }
    }
  }
</script>
<style lang="scss" scoped>
  .buttonstyle {
    cursor: pointer;
    margin-bottom: 15px;
    margin-left: 10px;
    padding: 10px 20px;
    font-size: 14px;
    border-radius: 3px;
    border: 1px solid red;
    background-color: white;
    color: red;
    outline: none;
  }

  .checked {
    border: 1px solid #13ce66;
    color: #13ce66;
    outline: none;
  }
</style>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

耶耶耶 2022-09-13 19:47:28

我很好奇,为啥在vue中,用jquery~~

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文