victor999's avatar

i try to mount a component in a component vue

i i try to mount a component in a component, this component its a partial, in especifict its a paginator, which i need to integrate, i use props in the paginate component. but i have a problem, in the console appears the next messagge "Failed to mount component: template or render function not defined." i am new in vue js, i using router-view i don´t know if this it is affecting en the problem the code its the next :

Pedido.vue

export default { data(){ return{ pedidos:[], pagination: { current_page: 1, }, } }, mounted() { console.log('Component mounted.') this.getData(); }, methods:{ getData(){ this.$Progress.start(); axios.get("api/pedidos?page=" + this.pagination.current_page) .then(response =>{ this.pedidos = response.data.data; this.pagination = response.data.meta; this.$Progress.finish(); }) .catch(e =>{ console.log(e) this.$Progress.fail(); }) //.then(({ data }) => (this.pedidos = data)); } }, }

PaginationComponent.vue

  • <a class="page-link" @click.prevent="changePage(1)" >First page
  • <a class="page-link" @click.prevent="changePage(pagination.current_page - 1)">Previous
  •         <li class="page-item" v-for="page in pages"  :key="page" :class="isCurrentPage(page) ? 'active' : ''">
                <a class="page-link" @click.prevent="changePage(page)">{{ page }}
                    <span v-if="isCurrentPage(page)" class="sr-only">(current)</span>
                </a>
            </li>
    
            <li class="page-item" :class="{ disabled: pagination.current_page >= pagination.last_page }">
                <a class="page-link" @click.prevent="changePage(pagination.current_page + 1)">Next</a>
            </li>
            <li class="page-item" :class="{ disabled: pagination.current_page >= pagination.last_page }">
                <a class="page-link" @click.prevent="changePage(pagination.last_page)">Last page</a>
            </li>
        </ul>
    </nav>
    

    export default { props:['pagination', 'offset'], template: '', methods: { isCurrentPage(page){ return this.pagination.current_page === page }, changePage(page) { if (page> this.pagination.last_page) { page = this.pagination.last_page; } this.pagination.current_page = page; this.$emit('paginate'); } }, computed: { pages() { let pages = []
                let from = this.pagination.current_page - Math.floor(this.offset / 2)
    
                if (from < 1) {
                    from = 1
                }
    
                let to = from + this.offset -1
    
                if (to > this.pagination.last_page) {
                    to = this.pagination.last_page
                }
    
                while (from <= to) {
                    pages.push(from)
                    from++
                }
    
                return pages
            }
        }
    }
    

    app.js

    Vue.component('pagination', require('./components/partial/PaginationComponent.vue'));

    the error: [Vue warn]: Failed to mount component: template or render function not defined.

    found in

    ---> at resources/js/components/Pedido.vue

    but in the extension of vue in the console i see the properties of the object, this is fine, but I do not know what I'm doing wrong, like I said I'm new to this.

    https://i.stack.imgur.com/j1lUm.png

    I hope they understand me, I would greatly appreciate your help.

0 likes
0 replies

Please or to participate in this conversation.