M
M
moskwin682019-04-28 16:00:19
Vue.js
moskwin68, 2019-04-28 16:00:19

How to conditionally render inside a VueJS component's template?

How to draw span id="wrong" when var wrong = true;

<div id="controls">
 <font-size-number target="headline" value="30" min="20" max="50"></font-size-number>
</div>

Vue.component('font-size-number', {
 props: [ 'target', 'min', 'max'],
 template: '<p><input type="number" @input="onChange" v-bind:id="`${target}-number`" class="set"><span id="wrong">Неверное значение</span></p>',
 methods: {
  onChange(e) {
   if (e.target.value < Number(this.min) | e.target.value > Number(this.max)) {
     var wrong = true;
     console.log(wrong);
   } 
  },
 },
});

new Vue({ 
  el: '#controls',
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2019-04-28
@moskwin68

Is it possible to get a higher education without having a secondary? Obviously not. How about mastering a front-end framework without having basic knowledge of html / js? Judging by the code shown, you are not aware that the id attributes must have unique values ​​( <span id="wrong">in the component template - and if there are several instances of the component?), You are confused with operators - you used a bitwise OR where there should have been a logical one. Maybe we should wait with vue and tighten up the basics?
And if you answer directly to your question ... Well, hold on .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question