1

I've got a copy of the object using Object.assign function inside a method (thanks to @Chris advice) as below: (It could be quill-editor or any other text input field)

<template>
  <div>
    <quill-editor
    v-model="itemsCopy[0].text"
    :options="editorOption"
    >
    </quill-editor> 
    {{itemsCopy[0].text}}
    <button @click="copyAndChange()"> </button>
  </div>
</template>


<script>


export default {
    data() {
        return {
            items: [
              {text: 'text1', active: true},
              {text: 'text1', active: true},
              {text: 'text1', active: true}
            ],
            itemsCopy [],
        }
    },
    methods: {
        function copyAndChange() {
          this.itemsCopy = this.items.slice();
          for (var i=0; i<this.itemsCopy.length; i++) {
            var obj = Object.assign({}, this.itemsCopy[i]);
            obj.text = "something";
            this.itemsCopy[i] = obj;  //replace the old obj with the new modified one.
            console.log('text from items: ' + this.items[i].text)
            console.log('text from itemsCopy: ' + this.itemsCopy[i].text)
          }
          return 0
        }
    }
}
</script>

Case1. I'm not running the function - all works

Case2. I'm running the function once - and I can see the "something" text within the editor, I can edit it, but the output inside {{itemsCopy[0].text}} are not changing...

After I run the function - I noticed I cannot edit the object's text field (and also active variable)

9
  • are you getting errors in console? Commented Feb 28, 2018 at 13:55
  • @F.bernal no, all is runnig as it should Commented Feb 28, 2018 at 13:56
  • do you have itemsCopy in s vue obj? Commented Feb 28, 2018 at 13:59
  • I don't really know what you mean... Commented Feb 28, 2018 at 14:00
  • 1
    see this example with your code.. (adapted) jsfiddle.net/tng9r8j3/99 Commented Feb 28, 2018 at 14:01

1 Answer 1

0

Well, you make a copy of items and don't do anything with that copy, from what I see.

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

1 Comment

yes, but If I'm trying to configure my editor v-model="items[0].text" it will output edited text into {{items[0].text}}, on new object it's now working. I don't know why..

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.