Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.0.18 change detection caveats #2549

Closed
taoche opened this issue Mar 23, 2016 · 1 comment
Closed

1.0.18 change detection caveats #2549

taoche opened this issue Mar 23, 2016 · 1 comment

Comments

@taoche
Copy link

taoche commented Mar 23, 2016

Vue.js version

1.0.18

parent component

<template>
  <div id="app">
    <img class="logo" src="./assets/logo.png">
    <hello :list="list"></hello>
  </div>
</template>

<script>
import Hello from './components/Hello'

export default {
  data () {
    return {
      list: [{
        name: 'test-example1',
        id: 1
      },
      {
        name: 'test-example2',
        id: 2
      },
      {
        name: 'test-example3',
        id: 3
      }]
    }
  },
  components: {
    Hello
  }
}
</script>

<template>
<div class="hello">
  <h1>{{ msg }}</h1>
  <li v-for="item in list" track-by="$index">{{item.name}}</li>
  <button @click="clickHandle">push item</button>
</div>
</template>

<script>
var mockData = {
  name: 'test',
  id: 'test',
  test: false
}

export default {
  props: ['list'],
  data () {
    return {
      msg: 'Hello World!'
    }
  },
  created () {
    // mock code
    this.list = this.list.map(item => {
      return {
        name: item.name,
        id: item.id,
        test: false
      }
    })
  },
  methods: {
    clickHandle () {
      this.list.push(mockData)
    }
  }
}
</script>

It can work in version 1.0.17 But in the 1.0.18 version, I click on the button .data is changed, but the list is no rendering

I do not see the changes for this feature for read the relase note
I do not know if I missed something, hoping to get answers

@yyx990803
Copy link
Member

This is fixed, however, mutating a passed down prop is not a recommended practice - it's best to treat props as immutable values and let its original owners do the mutation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants