1

I am new in vueJS and i try to implement my custom component in my laravel .blade.php file but it's not working My code like this

Vue.component('todo-item', {
        props: ['todo'],
        template: '<li>{{ todo.text }}</li>'
    })
    var app7 = new Vue({
        el: '#app-7',
        data: {
            groceryList: [
                {text: 'Vegetables'},
                {text: 'Cheese'},
                {text: 'Whatever else humans are supposed to eat'}
            ]
        }
    }) 

<div id="app-7">
<ol>
    <todo-item v-for="item in groceryList" v-bind:todo="item"></todo-item>
</ol>

i have add this same code in .html file then it's working

1
  • Are there any errors in the concole? Commented Feb 20, 2017 at 7:25

2 Answers 2

3

add @ before @{{ todo.text }} because if you not give "@" then it's count as laravel variable

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

Comments

1

I guess your getting an error like this

Use of undefined constant todo - assumed 'todo' 

this means that blade template engine mixed up with vue js template

{{ todo.text }}

blade considers this as its code but there is not any todo variable there

How to fix this :

Wrap your javascript code into a .js file and make sure your loading it just at the bottom of your blade file.

2 Comments

NO. i get error like this "The character encoding of the HTML document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the page must be declared in the document or in the transfer protocol." But i have already used <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1">
Question is not answered correctly, Adding @{{ todo.text }} solve php issue but Javascript error is thrown Uncaught ReferenceError: groceryList is not defined.

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.