• 1.问题分析:

      在vue之前,我们想要获取某一组(设置相同的name属性)radio的选中状态是通过name属性获取,判断input的checked是true还是false,但是当列表中有多组(动态获取)就显得很乏力;vue出现后我们可以通过v-model很巧妙的完成。
    
  • 2.vue中分析(完成代码请看后面)

      <input :name="item.COLUMN_CODE" :type="item.COLUMN_TYPE" v-model="item1.ISSELECT" value="true" :checked="item1.ISSELECT" :disabled="isAnswer" class="tui-checkbox">
    

    我们将name绑定COLUMN_CODE设置为同一组radio或checkbox;v-model绑定返回的值ISSELECT(true/false),value=‘true’表示当ISSELECT的值为true是该radio或checkbox就自动选中,同理,当我们选中某一项时对应的ISSELECT自动切换成true。
    vue官网描述的是无需设置name,但是我在项目中测试过是通不过的,因为还是无法识别是同一组还是不同组,所以建议读者 加上。

  • 3.完成代码(该例子中input是自定义的样式)

<div class="select-item" v-if="voteType == 'A' || voteType == 'B'" :key="index" v-for="(item, index) in detailList">
    <div class="family select-item-title" :attr="item.COLUMN_CODE" v-if="item.COLUMN_TYPE == 'radio'" v-html="item.COLUMN_NAME + '(单选)'"></div>
     <div class="family select-item-title" :attr="item.COLUMN_CODE" v-else-if="item.COLUMN_TYPE == 'checkbox'" v-html="item.COLUMN_NAME + '(多选)'"></div>
     <div class="family select-item-title" :attr="item.COLUMN_CODE" v-else v-html="item.COLUMN_NAME"></div>
     <div class="option-con" v-if="item.COLUMN_TYPE != 'text'" :key="index1" v-for="(item1, index1) in item.OPTION_LIST">
       <div class="option-con-row" v-if="item1.OPTION_TYPE != 'text'">
         <input :name="item.COLUMN_CODE" :type="item.COLUMN_TYPE" v-model="item1.ISSELECT" value="true" :checked="item1.ISSELECT" :disabled="isAnswer" class="tui-checkbox">
         <div class="family option-desc">{{item1.OPTION_NAME}}</div>
       </div>
       <div class="text-area-con" v-else>
         <div class="option-con-row">
           <input :name="item.COLUMN_CODE" :type="item.COLUMN_TYPE" v-model="item1.ISSELECT" value="true" :checked="item1.ISSELECT" :disabled="isAnswer" class="tui-checkbox">
           <div class="family option-desc">{{item1.OPTION_NAME}}</div>
         </div>
         <textarea class="text-area" rows="3" v-model="item1.OPTION_CONTENT" :readonly="isAnswer"></textarea>
       </div>
       <img class="option-con-img" v-if="item1.EMC_URL" :src="item1.EMC_URL">
     </div>
     <div class="option-con" v-if="item.COLUMN_TYPE == 'text'">
       <div class="text-area-con">
         <textarea class="text-area" rows="3" v-model="item.COLUMN_CONTENT" :readonly="isAnswer"></textarea>
       </div>
     </div>
   </div>
	/*radio或checked的样式:*/
	.checkbox-list-con .mint-msgbox-message{
	  line-height: 20px;
	}
	.checkbox-list-con span {
	  position: relative;
	  margin-right: 15px;
	}
	.checkbox-list-con .Checkbox {
	  position: absolute;
	  visibility: hidden;
	}
	.checkbox-list-con .Checkbox+label {
	  position:absolute;
	  width: 16px;
	  height: 16px;
	  border: 1px solid #A6A6A6;
	  border-radius: 50%;
	  background-color:#ffffff;
	}
	.checkbox-list-con .Checkbox:checked+label:after {
	  content: "";
	  position: absolute;
	  left: 2px;
	  top:2px;
	  width: 9px;
	  height: 4px;
	  border: 2px solid #00b7ee;
	  border-top-color: transparent;
	  border-right-color: transparent;
	  transform: rotate(-45deg);
	  -ms-transform: rotate(-60deg);
	  -moz-transform: rotate(-60deg);
	  -webkit-transform: rotate(-60deg);
	}
	
	.checkbox-list{
	  display: flex;
	  flex-direction: row;
	  margin-bottom: 5px;
	  align-items: center;
	  line-height: 20px;
	}
	.checkbox-list-con{
	  display: flex;
	  flex-direction: column;
	  padding: 10px 20px;
	}
	/*自定义checkbox*/
	
	.tui-checkbox:checked {
	  background:#1673ff
	}
	.tui-checkbox {
	  width:25px;
	  height:25px;
	  background-color:#ffffff;
	  border:solid 1px #dddddd;
	  -webkit-border-radius:50%;
	  border-radius:50%;
	  font-size:0.8rem;
	  margin:0;
	  padding:0;
	  position:relative;
	  display:inline-block;
	  vertical-align:top;
	  cursor:default;
	  -webkit-appearance:none;
	  -webkit-user-select:none;
	  user-select:none;
	  -webkit-transition:background-color ease 0.1s;
	  transition:background-color ease 0.1s;
	}
	.tui-checkbox:checked::after {
	  content:'';
	  top:5px;
	  left:5px;
	  position:absolute;
	  background:transparent;
	  border:#fff solid 2px;
	  border-top:none;
	  border-right:none;
	  height:6px;
	  width:10px;
	  -moz-transform:rotate(-45deg);
	  -ms-transform:rotate(-45deg);
	  -webkit-transform:rotate(-45deg);
	  transform:rotate(-45deg);
	}
	
	/*其他样式*/
	.score-result{
	   font-size: 16px;
	   font-weight: 600!important;
	   color: #2E8B57;
	   width: calc(100% - 40px);
	   padding: 10px 20px;
	   line-height: 20px;
	   background: #ffffff;
	 }
	 .text-area-con{
	   width: 100%;
	 }
	 .text-area{
	   width: calc(100% - 10px);
	   /*height: 80px;*/
	   padding: 5px;
	   outline: none;
	   resize: none;
	   font-size: 15px;
	   font-weight: 500;
	   color: #333333;
	   font-family: "Microsoft YaHei";
	   border: 1px solid #888888;
	 }
	 .appointment-btn {
	   position: relative!important;
	   font-size: 18px;
	   color: #ffffff;
	   text-align: center;
	   line-height: 44px;
	   height: 44px;
	   border-top: 1px solid #f2f2f2;
	   background: #366CB3;
	   width: calc(100% - 32px);
	   margin: 0px 0px 15px 16px;
	   border-radius: 3px;
	   letter-spacing: 4px;
	 }
	 .option-desc{
	   font-size: 15px;
	   margin-left: 20px;
	   width: calc(100% - 45px);
	   text-align: justify;
	   line-height: 24px;
	 }
	 .option-desc1{
	   font-size: 15px;
	   margin-left: 20px;
	   width: calc(100% - 45px);
	   text-align: justify;
	   line-height: 24px;
	   color: #F0686E;
	 }
	 .option-con-img{
	   width: calc(100% - 90px);
	   height: 140px;
	   margin-left: 45px;
	 }
	 .option-con-row{
	   display: flex;
	   align-items: center;
	   width: 100%;
	   padding: 10px 0px;
	 }
	 .option-con{
	   display: flex;
	   flex-direction: column;
	   align-items: flex-start;
	   width: calc(100% - 40px);
	   padding: 10px 20px;
	   border-top: 1px solid #efefef;
	 }
	 .select-item-title{
	   width: calc(100% - 40px);
	   padding: 10px 20px;
	   color: #4682B4;
	   text-align: justify;
	   font-size: 15px;
	   line-height: 24px;
	 }
	 .select-item{
	   display: flex;
	   flex-direction: column;
	   margin-bottom: 15px;
	   background: #ffffff;
	 }
	 .bottom-con{
	   display: flex;
	   flex-direction: column;
	   width: 100%;
	   background: #f2f2f2;
	 }
	 .top-four-img{
	   width: 16px;
	   height: 16px;
	 }
	 .top-four-title{
	   color: #434343;
	   font-size: 16px;
	   margin-right: 5px;
	 }
	 .top-four{
	   display: flex;
	   justify-content: center;
	   align-items: center;
	   background: #ffffff;
	   width: 100%;
	   padding: 15px 0px;
	 }
	 .top-three-content{
	   color: #333333;
	   font-size: 15px;
	   line-height: 28px;
	   text-indent:2em;
	   text-align: justify;
	 }
	 .top-three-desc{
	   color: #4682B4;
	   font-size: 15px;
	   line-height: 28px;
	   text-indent:2em;
	 }
	 .top-three{
	   width: calc(100% - 40px);
	   padding: 15px 20px 0px 20px;
	   background: #ffffff;
	   overflow: hidden;
	   text-overflow: ellipsis;
	   display: -webkit-box;
	   -webkit-line-clamp: 3;
	   -webkit-box-orient: vertical;
	 }
	 .top-three1{
	   width: calc(100% - 40px);
	   padding: 15px 20px 15px 20px;
	   background: #ffffff;
	 }
	 .top-two-time{
	   width: 100%;
	   text-align: center;
	   font-size: 13px;
	   color: #999999;
	   margin-bottom: 10px;
	 }
	 .top-two-title{
	   font-size: 18px;
	   color: 	#4682B4;
	   text-align: center;
	   width: 100%;
	   margin-bottom: 10px;
	   line-height: 24px;
	 }
	 .top-one>img{
	   height: 100%;
	   width: 100%;
	 }
	 .top-two{
	   width: calc(100% - 40px);
	   background: #ffffff;
	   padding:0px 20px;
	   border-bottom: 1px solid #efefef;
	 }
	 .top-one{
	   height: 100px;
	   width: 100%;
	 }
	 .top-con{
	   display: flex;
	   flex-direction: column;
	   justify-content: center;
	   align-items: center;
	   width: 100%;
	   margin-bottom: 15px;
	 }
	 .wrapper {
	   width: 100%;
	   height: 100%;
	   /*height: calc(100% - 70px);*/
	   overflow: auto;
	   background: #f2f2f2;
	   -webkit-overflow-scrolling: touch;
	 }
	 .container {
	   height: 100%;
	   background-color: #f2f2f2;
	   display: flex;
	   flex-direction: column;
	 }
Logo

前往低代码交流专区

更多推荐