the_ the_ - 1 year ago 36
Javascript Question

Vue not loading data

I have a vue/coffeescript app that looks like this:

There are no errors in the console, and it says it's making a successful external request for the JSON, however When I say

, it only returns as Test instead of coming from the JSON.

new Vue({
el: '#app',
data: {
showModal: false,
book: {
name: "Test",
description: "",
photo: ""

ready: () ->
console.log (

methods: {
getBookData: () ->
self = $(this)
$.getJSON 'GGPK4A.json', (data) -> = data



I don't know how to do it in coffeescript, but I think the issue is that this doesn't refer to Vue within the callback function, so setting isn't working. Normally you can fix this using .bind(this) on the function, or setting var vm = this before the ajax call and setting in the callback.