Victor Oliveira
Victor Oliveira

Reputation: 1129

Show value different from v-model on input

I have an input which I receive a value to access an array. But My array starts in 0 and I want my input to start in 1, how can I do that?

var vm = new Vue({
    el: '#test',
    data:{
        foo:0
    }
})

http://jsfiddle.net/xb5h545w/15/

Upvotes: 1

Views: 3041

Answers (1)

Joseph Silber
Joseph Silber

Reputation: 220136

Use a computed property:

new Vue({
    el: '#test',
    data: { foo: 0 },
    computed: {
        normalizedFoo: {
            get () {
                return this.foo + 1;
            },
            set (value) {
                this.foo = value - 1;
            }
        }
    }
});

Here's your updated fiddle: http://jsfiddle.net/xb5h545w/17/

Upvotes: 3

Related Questions