1

I want to show a message on my page with VueJS, but Laravel doesn't want to show it and sends me an error message :

Use of undefined constant message - assumed 'message' (this will throw an Error in a future version of PHP)

My index.blade.php :

<a v-bind:href="link"> {{ message }} </a>

My app.js :

new Vue({
    el: '#app',
    data: {
        message: 'Hello world',
    }
});
0

2 Answers 2

6

Your error appears because Laravel Blade tries to parse {{ message }} as PHP code. Laravel Blade and VueJS are sharing the same {{ }} syntax for showing variables.

In order to tell Blade that your {{ message }} is not PHP code, you either need to do this :

<a v-bind:href="link"> @{{ message }} </a>

or, if you have lots of VueJS code, you can surround your HTML with this :

@verbatim
    <a v-bind:href="link"> {{ message }} </a>
@endverbatim

Reference

Sign up to request clarification or add additional context in comments.

2 Comments

Isn't work too it's write {{ message }} instead of hello world :'(
@ValentinLeguy Make sure your <a> tag is indeed inside an element with the ID #app, as you defined in app.js
1
<a v-bind:href="link"> @{{ message }} </a>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.