vue做单选只能选一个

  1. <template>
  2. <div class="list">
  3. <!-- 多行多列单选 -->
  4. <span>只能选一个</span>
  5. <div class="list-group" v-for="(item,index) in items">
  6. <div class="left">
  7. <p>{{item.sex}}</p>
  8. </div>
  9. <div class="right" >
  10. <div class="right-box" v-for="list in item.introduce" @click="check(item,list,index)">
  11. <i class="iconfont" :class="checked == list.id?'icon-yuanyixuan':'icon-yuanweixuan'"></i>
  12. <p >{{list.name}}</p>
  13. </div>
  14. </div>
  15. </div>
  16. </div>
  17. </template>
  18. <script>
  19. export default{
  20. name: 'list',
  21. data() {
  22. return {
  23. checked: '',
  24. items: [
  25. {
  26. sex: '男爱豆',
  27. introduce: [
  28. {
  29. name: '易烊千玺',
  30. id: 1
  31. },
  32. {
  33. name: '张一山',
  34. id: 2
  35. },
  36. {
  37. name: '朱亚文',
  38. id: 3
  39. }
  40. ]
  41. },
  42. {
  43. sex: '女爱豆',
  44. introduce: [
  45. {
  46. name: '迪丽热巴',
  47. id: 4
  48. },
  49. {
  50. name: '杨紫',
  51. id: 5
  52. },
  53. {
  54. name: '郑爽',
  55. id: 6
  56. }
  57. ]
  58. }
  59. ]
  60. }
  61. },
  62. methods: {
  63. check(item,list,index) {
  64. this.checked = list.id;
  65. }
  66. }
  67. }
  68. </script>
  69. <style lang="less">
  70. .list {
  71. span {
  72. display: inline-block;
  73. width: 400px;
  74. text-align: center;
  75. margin-bottom: 10px;
  76. }
  77. .list-group {
  78. width: 400px;
  79. height: 50px;
  80. .left {
  81. float: left;
  82. width: 100px;
  83. }
  84. .right {
  85. float: right;
  86. width: 300px;
  87. .right-box {
  88. display: inline-block;
  89. width: 100px;
  90. p {
  91. display: inline-block;
  92. }
  93. .icon-yuanyixuan {
  94. color: red;
  95. }
  96. }
  97. }
  98. }
  99. }
  100. </style>

每行可以选一个

  1. <div class="list">
  2. <!-- 多行多列单选 -->
  3. <span>每行可以选一个</span>
  4. <div class="list-group" v-for="(item,index) in items">
  5. <div class="left">
  6. <p>{{item.sex}}</p>
  7. </div>
  8. <div class="right" >
  9. <div class="right-box" v-for="(list,index) in item.introduce" @click="check(item,list,index)">
  10. <i class="iconfont" :class="item.isChecked == index ?'icon-yuanyixuan':'icon-yuanweixuan'"></i>
  11. <p >{{list.name}}</p>
  12. </div>
  13. </div>
  14. </div>
  15. </div>

js

  1. export default{
  2. name: 'list',
  3. data() {
  4. return {
  5. checked: '',
  6. items: [
  7. {
  8. sex: '男爱豆',
  9. isChecked: 0,
  10. introduce: [
  11. {
  12. name: '易烊千玺',
  13. },
  14. {
  15. name: '张一山',
  16. },
  17. {
  18. name: '朱亚文',
  19. }
  20. ]
  21. },
  22. {
  23. sex: '女爱豆',
  24. isChecked: 1,
  25. introduce: [
  26. {
  27. name: '迪丽热巴',
  28. },
  29. {
  30. name: '杨紫',
  31. },
  32. {
  33. name: '郑爽',
  34. }
  35. ]
  36. }
  37. ]
  38. }
  39. },
  40. methods: {
  41. check(item,list,index) {
  42. item.isChecked = index;
  43. }
  44. }
  45. }

vue多选

  1. <div class="list">
  2. <span>终于可以多选了</span>
  3. <div class="list-group" v-for="(item,index) in items">
  4. <div class="left">
  5. <p>{{item.sex}}</p>
  6. </div>
  7. <div class="right" >
  8. <div class="right-box" v-for="(list,index) in item.introduce" @click="check(item,list,index)">
  9. <i class="iconfont" :class="item.isChecked.indexOf(index) != -1 ?'icon-yuanyixuan':'icon-yuanweixuan'"></i>
  10. <p >{{list.name}}</p>
  11. </div>
  12. </div>
  13. </div>
  14. </div>

js

  1. export default{
  2. name: 'list',
  3. data() {
  4. return {
  5. checked: '',
  6. items: [
  7. {
  8. sex: '男爱豆',
  9. isChecked: [0],
  10. introduce: [
  11. {
  12. name: '易烊千玺'
  13. },
  14. {
  15. name: '张一山'
  16. },
  17. {
  18. name: '朱亚文'
  19. }
  20. ]
  21. },
  22. {
  23. sex: '女爱豆',
  24. isChecked: [0],
  25. introduce: [
  26. {
  27. name: '迪丽热巴'
  28. },
  29. {
  30. name: '杨紫'
  31. },
  32. {
  33. name: '郑爽'
  34. }
  35. ]
  36. }
  37. ]
  38. }
  39. },
  40. methods: {
  41. check(item,list,index) {
  42. var tmpIndex = item.isChecked.indexOf(index);
  43. // -1就是选中状态
  44. if(tmpIndex != -1){
  45. item.isChecked.splice(tmpIndex,1);
  46. }else {
  47. item.isChecked.push(index);
  48. }
  49. }
  50. }
  51. }

vue多选框,实现添加和删除功能

  1. <div class="list">
  2. <span>可添加删除</span>
  3. <div class="list-group" v-for="(item,index) in items">
  4. <div class="left">
  5. <p>{{item.sex}}</p>
  6. </div>
  7. <div class="right" >
  8. <div class="right-box" v-for="(list,index) in item.introduce" @click="check(item,list,index)">
  9. <i class="iconfont" :class="choose.indexOf(list.name) != -1 ?'icon-yuanyixuan':'icon-yuanweixuan'"></i>
  10. <p >{{list.name}}</p>
  11. </div>
  12. </div>
  13. </div>
  14. <div class="list-group">
  15. <div class="left">
  16. <p>你的选择是</p>
  17. </div>
  18. <div class="right">
  19. ({{choose.join(',')}})
  20. </div>
  21. </div>
  22. </div>

js

  1. export default{
  2. name: 'list',
  3. data() {
  4. return {
  5. items: [
  6. {
  7. sex: '男爱豆',
  8. introduce: [
  9. {
  10. name: '易烊千玺'
  11. },
  12. {
  13. name: '张一山'
  14. },
  15. {
  16. name: '朱亚文'
  17. }
  18. ]
  19. },
  20. {
  21. sex: '女爱豆',
  22. introduce: [
  23. {
  24. name: '迪丽热巴'
  25. },
  26. {
  27. name: '杨紫'
  28. },
  29. {
  30. name: '郑爽'
  31. }
  32. ]
  33. }
  34. ],
  35. choose: []
  36. }
  37. },
  38. methods: {
  39. check(item,list,index) {
  40. var tmpIndex = this.choose.indexOf(list.name);
  41. // -1就是选中状态
  42. if(tmpIndex != -1){
  43. this.choose.splice(tmpIndex,1)
  44. }else {
  45. this.choose.push(list.name);
  46. }
  47. }
  48. }
  49. }

vue单选,多选,多选的内容显示在页面可删除的更多相关文章

  1. AS修改text内容+显示不同页面

    新创建一个project,命名为myclass. 一:修改 在res中找到layout打开xml文件,右上角有一个code,点击进入可以写代码的文件,并在里面进行修改.(老版本写代码的界面在下面与de ...

  2. Vue表单绑定(单选按钮,选择框(单选时,多选时,用 v-for 渲染的动态选项)

    <!DOCTYPE html><html>    <head>        <meta charset="utf-8">      ...

  3. vue.js实现单选框、复选框和下拉框

    Vue.js可以很方便的实现数据双向绑定,所以在处理表单,人机交互方面具有很大的优势.下边以单选框.复选框和下拉框为例介绍他们在HTML和Vue.js中的具体实现方式. 一.单选框   在传统的HTM ...

  4. vue中单选框与多选框的实现与美化

    我们在做一些页面时,可能会用到很多的单选框和复选框,但是原生的radio和checkbox前面的原型图标或方框样式不尽人意.于是,决定自己来实现单选框和复选框.我用的是vue,所以就用vue的方式实现 ...

  5. CSS学习笔记三:自定义单选框,复选框,开关

    一点一点学习CCS,这次学习了如何自定义单选框,复选框以及开关. 一.单选框 1.先写好body里面的样式,先写几个框 <body> <div class="radio-1 ...

  6. 自动化测试-15.selenium单选框与复选框状态判断

    本篇主要介绍单选框和复选框的操作 一.认识单选框和复选框 1.先认清楚单选框和复选框长什么样 2.各位小伙伴看清楚哦,上面的单选框是圆的:下图复选框是方的,这个是业界的标准,要是开发小伙伴把图标弄错了 ...

  7. 2.12 单选框和复选框(radiobox、checkbox)

    2.12 单选框和复选框(radiobox.checkbox) 本篇主要介绍单选框和复选框的操作一.认识单选框和复选框    1.先认清楚单选框和复选框长什么样 2.各位小伙伴看清楚哦,上面的单选框是 ...

  8. Selenium2学习(十五)-- 单选框和复选框(radiobox、checkbox)

    本篇主要介绍单选框和复选框的操作 一.认识单选框和复选框 1.先认清楚单选框和复选框长什么样 2.各位小伙伴看清楚哦,上面的单选框是圆的:下图复选框是方的,这个是业界的标准,要是开发小伙伴把图标弄错了 ...

  9. 用Vue的方式实现复选框

    var borrVm = new Vue({ el: "#WingApp", data: { returnBookList:[], checked:"", ch ...

随机推荐

  1. Qt Widgets、QML、Qt Quick的区别

    Qt Widgets.QML.Qt Quick的区别 简述 看了之前关于 QML 的一些介绍,很多人难免会有一些疑惑: Q1:QML 和 Qt Quick 之间有什么区别? Q2:QtQuick 1. ...

  2. POJ.3468 A Simple Problem with Integers(线段树 区间更新 区间查询)

    POJ.3468 A Simple Problem with Integers(线段树 区间更新 区间查询) 题意分析 注意一下懒惰标记,数据部分和更新时的数字都要是long long ,别的没什么大 ...

  3. 解决win7 64位操作系统下安装PL/SQL后连接报错问题: make sure you have the 32 bits oracle client installed

    1. 在Oracle官网(http://www.oracle.com/technetwork/topics/winsoft-085727.html)下载文件: instantclient-basic- ...

  4. dfs序七个经典问题(转)

    我这个人不怎么喜欢写轻重链剖分和LCT 还是喜欢dfs序.括号序列之类的 毕竟线段树好写多了 然后就有了这篇转载的文章 写在这边以后有时间看看 原文链接:https://www.cnblogs.com ...

  5. [CEOI2004]锯木厂选址

    link 试题分析 做这种题就应该去先写个暴力代码 #include<iostream> #include<cstring> #include<cstdio> #i ...

  6. pycrypto 安装

    https://www.dlitz.net/software/pycrypto/ 下载pycrypto-2.6.1.tar.gz,解压后 python setup.py build python se ...

  7. 图像处理之Canny边缘检测

    http://blog.csdn.net/jia20003/article/details/41173767 图像处理之Canny 边缘检测 一:历史 Canny边缘检测算法是1986年有John F ...

  8. (转)IOS 的一些资源汇总

      UI界面类项目: Panoramagl —— 720全景展示 Panorama viewer library for iPhone, iPad and iPod touch MBProgressH ...

  9. Codeforces Round #385 (Div. 2)A B C 模拟 水 并查集

    A. Hongcow Learns the Cyclic Shift time limit per test 2 seconds memory limit per test 256 megabytes ...

  10. STM32自动生成精美图案

    http://note.youdao.com/noteshare?id=65f237225624d22fe18f4aaaeec8db07