VueJs Tutorials
- VueJs
- VueJs Instance
- Templates
- Component
- Computed Properties
- Watch Property
- Binding
- Events
- Rendering
- Directives
- Mixins
- Reactive Interface
- String Length
- Onchange Events
- Ternery Operator
- Global variable
- Get data attribute value
- String to array
- How to Get Array Length
- call a function on Page load
- current Date and Time
- Replace String
- Open link on new tab
- setTimeout in Vue JS
- object or array empty or not
- get element by id
- Laravel Vue Flash Message
How to use ternary operator?
Using v-model
File name : index.php
<!DOCTYPE html>
<html>
<head>
<title>How to use ternary operator in Vuejs?</title>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
</head>
<body>
<div id="app">
<input type="text" v-model="$data[ConditionTest ? 'firstname' : 'lastname']">
<div>First Name: {{ firstname }}</div>
<div>Last Name: {{ lastname }}</div>
</div>
<script type="text/javascript">
var app = new Vue({
el: '#app',
data: {
firstname: '',
lastname: '',
ConditionTest:true
}
})
</script>
</body>
</html>
Example
File name : index.php
<!DOCTYPE html>
<html>
<head>
<title>How to use ternary operator in Vuejs</title>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
</head>
<body>
<div id="appid">
<div>Name: {{ val == 1 ? 'mahtab' : 'Habib' }}</div>
</div>
<script type="text/javascript">
var app = new Vue({
el: '#appid',
data: {
val:1
}
})
</script>
</body>
</html>
File name : index.php
File name : index.php