vue.js - How can I get data inside of Vue from database like config or smth> -


var app = new vue({     el: '#app',      data: {         positions: []     },      created() {          axios.get('/config').then(function(response) {             this.$set(this.positions, "positions", response.data[0].dragedpositions);         });          console.log(this.positions.positions);     }  }); 

i have configs app in database , want use them inside of vue instance (here positions of elements). when im getting "this.positions.positions" im getting empty string.. how can that?

sounds want load config first , bootstrap application after that. use propsdata this:

axios.get('/config').then(function(response) {   new vue({     el: '#app',     props: ['positions'],     propsdata: {       positions: response.data[0].dragedpositions     },     created() {       console.log(this.positions);     }   }); }); 

i created little demo :)

const axios = {get () {    return promise.resolve({data: [{dragedpositions: [1,2]}]})  }}    axios.get("/config").then(function(response) {    new vue({      el: "#app",      props: ['positions'],      propsdata: {        positions: response.data[0].dragedpositions      },      created() {        console.log('created hook', this.positions);      }    });  });
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.3.4/vue.min.js"></script>    <pre id="app">positions = {{ positions }}</pre>


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -