D
D
Dauren S2019-01-04 08:08:01
Vue.js
Dauren S, 2019-01-04 08:08:01

How to get attribute in Vue.js on component initialization?

<div id="app" class="ui segment">
                   <div data-bullshit-attribute="<?=$model->title;?>" ref="div"></div>
       <?php if($model->lastfile->num):?>
       <div data-lastnum-attribute="<?=$model->lastfile->num;?>" ref="div2"></div>
       <?php else:?>
       <div data-lastnum-attribute="0" ref="div2"></div>
       <?php endif;?>
      <div v-for="(user, index) in users">
      	<div class="ui grid object_target">
      			
      			<div class="four wide column field">
      				 <?= $form->field($model4, 'file[]')->fileInput(['multiple' => true, 'accept' => 'image/*']) ?>
      			</div>
      			<div class="two wide column field">
      				<label style="font-weight: normal;font-size: 14px;" >Номер</label>
      			    <input type="text" v-model="user.procent"    disabled="disabled"  name="dirFiles[num][]"    />
      			
      			</div>
      			<div class="four wide column field">
      			    
      				<?= $form->field($model4, 'date_dog[]')->textInput(['maxlength' => true,'type'=>'date','disabled'=>$disabled,'value'=>date('Y-m-d',time()) ]);?>
      			</div>
      			<div class="three wide column field">
      			   
      				<?= $form->field($model4, 'cat_id[]')->dropDownList($dops,$params_cat_dop);?>
      			</div>
      			<div class="one wide column field">
      				 <p @click="deleteUser(index)" class="ui button red" style="margin-top:20px;">
                <i class="ui icon trash"></i>
              </p>
      			</div>
      	</div>
         
       
      
       
      </div>
      
      <p @click="addUser" class="ui button">
        +
      </p>
      
      
    </div>

new Vue({
  el: '#app',
  data: {
    users: [{ name: '',procent:'' }],
    message:'1',
     
  },
  methods: {
      addUser(index) {
      
      	var vm = this
  
      	this.users.push({
       	 	name: '',
        	procent: this.users.length+1,
    	});
    },
    deleteUser: function (index) {
      console.log(index);
      console.log(this.finds);
      this.users.splice(index, 1);
      if(index===0)
      this.addUser()
    },
  
  },
   computed: {
      percentTotal() {
      
      return this.users.reduce((acc, user) => acc + parseInt(user.procent, 10), 0)
      },
 	},
});

How to immediately find out the value of data-lastnum-attribute when initializing the component, and put it in the input percentage?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey delphinpro, 2019-01-04
@dauren101

this.$refs.div2.dataset.lastnumAttribute

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question