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

vue实现类似angular服务的方法 #4

Open
Wscats opened this issue Oct 8, 2016 · 0 comments
Open

vue实现类似angular服务的方法 #4

Wscats opened this issue Oct 8, 2016 · 0 comments

Comments

@Wscats
Copy link
Owner

Wscats commented Oct 8, 2016

var kinds = [{
            "id": "1",
        }, {
            "id": "2",
        }, {
            "id": "3",
        }, {
            "id": "4",
        }]
var Click = function() {
            console.log("hello wsscat")
        }
var demo = new Vue({
            el: '#demo',
            data: {
                kinds,
            },
            methods: {
                Click,
            }
        })

上面我们把需要复用的方法和数据在Vue构造器外部并之前定义,就可以达到在每个Vue()里面复用

<ul>
            <li v-for="kind in kinds">
                {{kind.id}}
            </li>
        </ul>
        <button @click="Click()">Wsscat</button>

这种就相当于angular定义的服务可以复用数据和方法

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

1 participant