简体   繁体   中英

accessing vue js object in javascript

In a Laravel blade template I can access some data using @{{list.length}}.

<template id="events-template">
      @{{list.length}}
</template>

How do I use this within a javascript function within the same view template?

Vue is defined in app.js as

var vm = new Vue({
    el: 'body',

});

app.js is called before the script in my view template

First, be sure that you actually have defined the list var in your vue instance

data: {
    list: []
}

Then, to access the list var, use the instance scope, for example in some method

methods: {
    someMethod: function () {
        console.log(list) // undefined
        console.log(this.list) // []
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM