Using vue. js to change the selected status, vue. js is selected

Source: Internet
Author: User

Using vue. js to change the selected status, vue. js is selected

After using the prototype to change the unselected status and accessing vue, you can think about whether you can use vue to implement the function. The page in the previous article does not dynamically implement the page, all data is directly written in html. After vue is used, the page can be dynamically generated based on the amount of data. The amount of code is also greatly reduced.

Html code:

<div data-role="page " class="page ">  <div class="center " id="app">  <div class="group ">  <ul>  <li v-for = "todo in todos ">   <div class="groupheader ">   <div class="Gheadertext ">{{todo.groupheader}}</div>   </div>   <div class = "groupbody ">   <ul class="list ">   <li v-for="cell in todo.groupbody" v-on:click="exchange($event)" class="groupcell">   <div class="celltext">    {{ cell.text }}   </div>      </li>   </ul>   </div>   </li>  </ul>  </div>  </div> </div> 

Data Code:

Var datas = {todos: [{groupheader: 'mb3101 ', groupbody: [{text: 'improperly adjusted'}, {text: 'photoelectric switch corrupt '}, {text: 'mirror gray '}, {text: 'improperly adjusted'}, {text: 'photoelectric switch damaged '}, {text: 'mirror gray'}, {text: 'improperly adjusted '}, {text: 'photoelectric switch damaged'}, {text: 'mirror gray '},]}, {groupheader: 'mb3102', groupbody: [{text: 'improperly adjusted '}, {text: 'photoelectric switch damaged'}, {text: 'mirror gray '}, {text: 'improperly adjusted '}, {text: 'optical switch damaged '}, {text: 'mirror gray'}, {text: 'improperly adjusted '}, {text: 'photovoltaic switch damaged '}, {text: 'mirror gray '},]}, {groupheader: 'mb3103', groupbody: [{text: 'improperly adjusted '}, {text: 'optical switch damaged '}, {text: 'mirror gray'}, {text: 'improperly adjusted '}, {text: 'photovoltaic switch damaged'}, {text: 'mirror gray '}, {text: 'improperly adjusted'}, {text: 'photoelectric switch damaged '}, {text: 'mirror gray'},]}

Js Code:

New Vue ({el: '# app', data: datas, methods: {exchange: function (event) {// obtain the clicked Element Object var a = event.tar get; // obtain the child element  var cellimg =. getElementsByTagName ("img") [0]; if (. className = "groupcell") {. className = "selectcell"; cellimg. style. display = "block";} else if (. className = "selectcell") {. className = "groupcell"; cellimg. style. display = "none ";}}}})

Effect:

The above method of using vue. js to change the selected status is all the content that I have shared with you. I hope to give you a reference and support for the customer's house.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.