я пытаюсь смонтировать компонент в компонент Vue - PullRequest
0 голосов
/ 19 июня 2019

ii. Попробуй смонтировать компонент в компоненте, этот компонент является его частичным, в частности это paginator, который мне нужно интегрировать, я использую реквизиты в компоненте paginate.но у меня проблема, в консоли появляется следующее сообщение «Не удалось смонтировать компонент: шаблон или функция визуализации не определены».я новичок в vue js, я использую router-view, я не знаю, если это влияет на проблему, код следующий:

Pedido.vue

<template>
  <div id="pedido" style="margin-top:50px">
    <div class="row justify-content-center">
      <div class="col-md-12">
        <div class="card">
          <div class="card-header">
            <h4 class="card-title">Pedidos</h4>
            <div class="card-tools" style="position: absolute;right: 1rem;top: .5rem;">
              <button type="button" class="btn btn-info" >
                Nuevo
                <i class="fas fa-plus"></i>
              </button>
              <button type="button" class="btn btn-primary" >
                Recargar
                <i class="fas fa-sync"></i>
              </button>
            </div>
          </div>

          <div class="card-body">
            <div class="mb-3">
              <div class="row">
                <div class="col-md-2">
                  <strong>Buscar por :</strong>
                </div>
                <div class="col-md-3">
                  <select  class="form-control" id="fileds">
                    <option value="total">Codigo</option>
                    <option value="name">Nombre</option>
                    <option value="email">Apellido</option>
                    <option value="phone">Telefono</option>
                    <option value="address">Direccion</option>
                     </select>
                </div>
                <div class="col-md-7">
                  <input  type="text" class="form-control" placeholder="Buscar">
                </div>
              </div>
            </div>
            <div class="table-responsive">
              <table class="table table-hover table-bordered table-striped">
                <thead>
                  <tr>
                    <th scope="col">Codigo</th>
                    <th scope="col">Nombre</th>
                    <th scope="col">Apellido</th>
                    <th scope="col">Telefono</th>
                    <th scope="col">Rut</th>
                    <th scope="col" class="text-center">Action</th>
                  </tr>
                </thead>
                <tbody>
                <tr v-for="(pedido, index) in pedidos" :key="pedido.codigo">
                    <th scope="row">{{ index + 1}}</th>
                    <td>{{ pedido.nombre_cliente}}</td>
                    <td>{{ pedido.apellido_cliente }}</td>
                    <td>{{ pedido.telefono_cliente}}</td>
                    <td>{{ pedido.rut_cliente }}</td>
                    <td class="text-center">
                      <button type="button"  class="btn btn-info btn-sm">
                        <i class="fas fa-eye"></i>
                      </button>
                      <button type="button"  class="btn btn-primary btn-sm">
                        <i class="fas fa-edit"></i>
                      </button>
                      <button
                        type="button"
                        
                        class="btn btn-danger btn-sm"
                      >
                        <i class="fas fa-trash-alt"></i>
                      </button>
                    </td>
                  </tr>
                  <tr >
                    <td colspan="6">
                      <div class="alert alert-danger" role="alert">No se ah encontrado resultados  :(</div>
                    </td>
                  </tr>
  </tbody>
</table>

<div class="card-footer">
                <pagination
                v-if="pagination.last_page > 1"
                :pagination="pagination"
                :offset="5"
                @paginate="getData()"
              ></pagination>
               
              </div>
      
            </div>

          

          </div>
        </div>
      </div>
    </div>
   
    
   
  </div>
</template>

<script>

    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));
          }
        },
    }
</script>

это его PaginationComponent.vue:

<template>
    <nav aria-label="...">
        <ul class="pagination justify-content-center">
            <li class="page-item" :class="{ disabled: pagination.current_page <= 1 }">
                <a class="page-link" @click.prevent="changePage(1)"  >First page</a>
            </li>
            <li class="page-item" :class="{ disabled: pagination.current_page <= 1 }">
                <a class="page-link" @click.prevent="changePage(pagination.current_page - 1)">Previous</a>
            </li>

            <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>
</template>

<script>
    export default {
        props:['pagination', 'offset'],
        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
            }
        }
    }
</script>

app.js

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

const app = new Vue({
    el: '#app',
    router
});

это ошибка

но в расширении vue в консоли я вижу свойства объекта, этохорошо, но я не знаю, что я делаю неправильно, как я сказал, что я новичок в этом.

расширение vue

Надеюсь, они меня поймут, я был бы очень признателен за вашу помощь.

Ответы [ 3 ]

0 голосов
/ 20 июня 2019

В файле app.js, кроме вас, укажите , где вы монтируете свой компонент (в данном случае в div с идентификатором "app"), вам также нужно указать Vue что для рендеринга.

Ваш компонент в файле app.js должен включать шаблон или функцию рендеринга, поэтому вы получаете сообщение об ошибке «Не удалось смонтировать компонент: шаблон или функция рендеринга не определены.

Вы можете добавить это так:

const app = new Vue({
  el: '#app',
  router,
  template: '<pagination/>'
});

Или используя функцию рендеринга следующим образом:

import Pagination from './components/partial/PaginationComponent.vue'

const app = new Vue({
  el: '#app',
  router,
  render: (h) => h(Pagination)
});
0 голосов
/ 20 июня 2019

хорошо, я пытался с их ответом, но не работал, Мне удалось решить это, добавив:

Vue.component ('pagination', require ('./ components / частичный / PaginationComponent.vue'). Default);

0 голосов
/ 20 июня 2019

Pedido.vue

export default {
  components: { pagination },
  data(){ ....

возможно это проблема

...