1

I have this data: Sample = [1,2,3]

one input, and and two button

The button are next data and previous

So the idea is to two way bind the input to Sample[var], where var is changeable via the button,

I've been trying to use compute setter or bind the array with changeable var in the data, with no success, what approach should I take?

here's the code:

<ckeditor v-model="thedata"></ckeditor>

data() {
    return {
        Sample: [1,2,3],
        thedata: Sample[var],
        var : 0
    }
}

2 Answers 2

2

Let me try to help you. So, you want the value of thedata is based on Sample and var, right?

You can try this code :

<template>
  <input v-model="thedata" type="text" />
</template>

<script>
export default {
  data() {
    return {
      Sample: [1, 2, 3],
      var: 0,
      thedata: '',
    };
  },
 
  mounted() {
    this.thedata = this.Sample[this.var];
  },
};
</script>  

You can useY mounted() and then combine the data.

Sign up to request clarification or add additional context in comments.

Comments

0
<ckeditor v-model="sample[index]"></ckeditor>
data() {
    return {
        sample: [1,2,3],
        index: 0
    }
}

1 Comment

Can I simplify it by moving the calculation to computed property?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.