Get started - v-model directive
v-model directive
Install
v.usePlugin()
method.require('valyrian.js');
let VModel = require('valyrian.js/plugins/v-model.js');
v.usePlugin(VModel);
Input
let obj = {
input: ''
};
<input type="text" v-model={[obj, 'input']} />
<p>Message: {obj.input}p>
Message:
Textarea
let obj = {
textarea: ''
};
<textarea v-model={[obj, 'textarea']} placeholder="Add some text"/>
<p>Multiline message: {obj.textarea}p>
Multiline message:
Boolean checkbox
let obj = {
check: true
};
<input type="checkbox" id="booleanCheckbox" v-model={[obj, 'check']} />
<label for="booleanCheckbox">{obj.check}label>
Non boolean checkbox
let obj = {
check: ''
};
<input type="checkbox" id="otherTypeCheckbox" value="Hello world" v-model={[obj, 'check']} />
<label for="otherTypeCheckbox"> Message: {obj.check}label>
Multiple checkboxes
let obj = {
check: []
};
<input type="checkbox" id="jack" value="Jack" v-model={[obj, 'check']}/>
<label for="jack">Jacklabel>
<input type="checkbox" id="john" value="John" v-model={[obj, 'check']}/>
<label for="john">Johnlabel>
<input type="checkbox" id="mike" value="Mike" v-model={[obj, 'check']}/>
<label for="mike">Mikelabel>
<br />
<span>Checked names: [{obj.check.join(', ')}]span>
Checked names: []
Radio
let obj = {
radio: ''
};
<input type="radio" id="hello" value="Hello" v-model={[obj, 'radio']} />
<label for="hello">Hellolabel>
<input type="radio" id="world" value="World" v-model={[obj, 'radio']} />
<label for="world">Worldlabel>
<br />
<span>Picked value: {obj.radio}span>
Picked value:
Select
let obj = {
select: ''
};
<select v-model={[obj, 'select']}>
<option disabled value="">Select an itemoption>
<option value="D">Aoption>
<option>Boption>
<option>Coption>
select>
<span>Selected: {obj.select}span>
Selected: Multiple select
let obj = {
select: []
};
<select v-model={[obj, 'select']} multiple>
<option value="D">Aoption>
<option>Boption>
<option>Coption>
select>
<span>Selected: [{obj.select.join(', ')}]span>
Selected: []