Join the Stack Overflow Community
Stack Overflow is a community of 6.6 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I've just started learning Vue, and have been following there intro guide, but am stuck at the:

Just open up your browser’s JavaScript console and set app.message to a different value.

I tried app.message = 'test' in Chrome's console, and it returns "test", but the text doesn't change in the browser.

Also when I just run app.message before setting it to "test", it returns undefined.

app.js

require('./bootstrap');

const app = new Vue({
    el: '#app',
    data: {
      message: 'Hello Vue!'
    }
});

./bootstrap

window._ = require('lodash');

window.$ = window.jQuery = require('jquery');
require('bootstrap-sass');

window.Vue = require('vue');
require('vue-resource');

Vue.http.interceptors.push((request, next) => {
    request.headers.set('X-CSRF-TOKEN', Laravel.csrfToken);

    next();
});

test.blade.php

@extends('layouts.app')

@section('content')
<div id="app">
  @{{ message }}
</div>
@endsection

I'm guessing its something to do with what Laravel does since when I start a standalone html file it works as Vue says. I'm also new to Laravel so not to sure what's going on here.

Using Vue 2 and Laravel 5.3

share|improve this question
    
What about this const app = new Vue({ data: {// your data} }).$mount('#app') – Belmin Bedak Nov 22 '16 at 8:55
    
what's the html that the php file outputs? – PanJunjie潘俊杰 Nov 22 '16 at 9:13
    
@PanJunjie潘俊杰 here is the html output: pastebin.com/dShmALK2 – Mint Nov 22 '16 at 18:32
    
@Belmin does the same thing :( – Mint Nov 22 '16 at 18:34
    
Can you given a working link, maybe host it somewhere as you say its working on the HTML file and seems laravel specific, we might be able to debug properly after we can access the console of the page. – SuperNOVA Nov 22 '16 at 20:20
up vote 1 down vote accepted

Well, as far as I can see from the live link is that its not the problem you anticipated at all. app returns an HTML element collection and not a Vue object. Try logging $vm(the Vue object) in your console and you will see the difference. Maybe, try renaming the object from const app to vue(lowercase) as I think you(or the package manager or something) have used app somewhere else.

The reason why app.message returns "test" on console is that every console statement returns something. It returns undefined first because app(The HTML collection) doesn't have a property named message.

Your live link console

share|improve this answer
    
Legend! Also any idea why test = new Vue works but var test = new Vue doesn't? (as in the Vue guide they use var. – Mint Nov 22 '16 at 22:54
1  
In one word, scope. When you use var test the variable declared is localized to the block it is declared in. When you don't use var, you are simply decalred as global therby being accessible in console. You can also try window.test=new Vue() ; – SuperNOVA Nov 22 '16 at 22:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.