search

Home  >  Q&A  >  body text

javascript - Can't js be introduced into the vue project to control the class of elements?

This is the situation of the console in the imported js

This is the case in elements

nav has not changed either.
How is this going?

曾经蜡笔没有小新曾经蜡笔没有小新2766 days ago953

reply all(3)I'll reply

  • 仅有的幸福

    仅有的幸福2017-07-05 10:44:02

    I don’t see where the problem is. When asking questions, first clarify your thoughts and expose the problem points.

    Answer questions

    Can’t js be introduced into the vue project to control the class of elements?

    It is possible to introduce tools such as jQuery to operate the dom

    reply
    0
  • 仅有的幸福

    仅有的幸福2017-07-05 10:44:02

    In fact, it is very convenient to deal with such problems in VueJS, here is an example.

    View online https://jsfiddle.net/wqbtt12c/

    The specific code is as follows:

    <p id="app">
      <p :class="classStr" @click="changeClass">点我</p>
    </p>
    const classPool = ['red', 'blue', 'yellow'];
    
    new Vue({
        el: '#app',
      data() {
          return {
            classStr: 'red'
        }
      },
      methods: {
          changeClass() {
            this.classStr = classPool[Math.ceil(Math.random()*3.0) - 1];
        }
      }
    });
    #app > p {
      width: 100px;
      height: 100px;
      line-height: 100px;
      text-align: center;
    }
    .red {
      background: red;
    }
    
    .blue {
      background: blue;
    }
    
    .yellow {
      background: yellow;
    }

    reply
    0
  • 过去多啦不再A梦

    过去多啦不再A梦2017-07-05 10:44:02

    In the vue project, the operation must be mounted after the element to be operated is mounted. I fainted.

    reply
    0
  • Cancelreply