Reputation: 245
There is such an example.When you click on the "add note" button, it checked whether the input is empty or not and adds a block with text entered into the input.
How to make the same example without using v-bind because it does not work in framework7?
Tried to do something like that but it doesn't work.
et getCat = document.getElementByClassName('inputCat').value;
let newCat = this.getCat;
this.cats.push(this.newCat);
this.newCat = '';
this.saveCats();
A working example with v-model
<f7-block v-for="(cat, n) in cats">
<span class="cat">{{ cat }}</span>
<f7-button fill color="red" @click="removeCat(n)">Удалить</f7-button>
</f7-block>
<f7-list form>
<f7-list-input
class="inputCat"
v-model="newCat"
type="text"
placeholder="Заметка"
></f7-list-input>
<f7-button fill color="blue" @click="addCat">Добавить заметку</f7-button>
</f7-list>
export default {
data() {
return{
cats:[],
newCat: null
}
},
mounted() {
if (localStorage.getItem('cats')) {
try {
this.cats = JSON.parse(localStorage.getItem('cats'));
} catch(e) {
localStorage.removeItem('cats');
}
}
},
methods: {
addCat() {
// убедиться, что было что-либо введено
if (!this.newCat) {
return;
}
this.cats.push(this.newCat);
this.newCat = '';
this.saveCats();
},
removeCat(x) {
this.cats.splice(x, 1);
this.saveCats();
},
saveCats() {
const parsed = JSON.stringify(this.cats);
localStorage.setItem('cats', parsed);
}
}
}
Upvotes: 1
Views: 4721
Reputation: 7690
According to the Framework7 documentation the @input event is used.
export default {
data() {
newCat: null;
}
}
<template>
<f7-list form>
<f7-list-input
class="inputCat"
:value="newCat"
@input="newCat = $event.target.value"
type="text"
placeholder="Заметка"
></f7-list-input>
<f7-button fill color="blue" @click="addCat">Добавить заметку</f7-button>
</f7-list>
</template>
Upvotes: 1