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

Conflicting method and data names. #565

Closed
crswll opened this issue Nov 17, 2014 · 2 comments
Closed

Conflicting method and data names. #565

crswll opened this issue Nov 17, 2014 · 2 comments

Comments

@crswll
Copy link

crswll commented Nov 17, 2014

I'm not sure this is a real issue but I figured I'd mention it either way.

When there's a method with the same name as a data property they conflict in a weird way. The method call works at first, then doesn't.

Here's an example:

new Vue({
    el: '#app',
    data: {
        id: 2,
        name: "Ted",
        color: "#000"
    },
    methods: {
        color: function () {
            this.$data.color = '#f00';
        }
    }
});
<div id="app">
    <div v-attr="data-id: id" v-style="color: color" v-on="click:color()">
        {{ name }}
    </div>
</div>

Here it is in a fiddle: http://jsfiddle.net/gk727vge/3/

@yyx990803
Copy link
Member

Both data properties and methods will be set on the instance, so the short answered is: don't use conflicting names :)

@crswll
Copy link
Author

crswll commented Nov 17, 2014

Makes sense! I just wanted to make sure it wasn't something more insidious.

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