I have an error Vuejs shows me console but in sight - laravel

0

Template.html

<div class="container">
      <table class="table table-striped">
  <thead>
    <tr>
      <th scope="col">#</th>
      <th scope="col">Nombre completo</th>
      <th scope="col">Telefono</th>
      <th scope="col">Dirección</th>
      <th scope="col">Pago</th>
      <th scope="col">Opciones</th>
    </tr>
  </thead>
  <tbody>
    <tr v-for="item in orden.data"  >
      <th scope="row">{{ item.id}}</th>
      <td>{{item.name}}  {{item.last_name}}</td>
      <td>{{item.Celular}}</td>
      <td>{{item.Direccion}}</td>
      <td>{{item.pay}}</td>
      <td> <button type="btn btn-primary" data-toggle="modal" data-target="#exampleModalCenter" v-on:click="showgetcompra(item)">Reporte</button></td>
    </tr>
  </tbody>
</table>

Modal

<div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="exampleModalCenterTitle">Modal title</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">

                <div v-for="items in vercompra.data">
                    <h1>hola {{items.Orden["0"].Img_Produ}}</h1>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                <button type="button" class="btn btn-primary">Save changes</button>
            </div>
        </div>
    </div>
</div>
<pagination data="orden" @pagination -change-page="fetchData"></pagination>

Script.JS

<script>
    export default {
        mounted() {
            this.fetchData(),
            this.showgetcompra(),
            this.timer = setInterval(

                this.fetchData, 10000)
            console.log(this.timer)
        },
        data ( ){
            return {
                orden: [],
                vercompra:[],
                timer: '',
                loading: false

            }
        },
        methods:{

            fetchData(page){

                if (typeof page === 'undefined') {
                    page = 1;
                }

                axios.get('/api/cart?page='+page)
                .then((res)=>{

                    this.orden = res.data
                    console.log(res.data)
                })
                .catch((err)=>{
                    console.log(err)
                })
            },
            cancelAutoUpdate: function() { 
                clearInterval(this.timer) 
            },

             beforeDestroy() {
             clearInterval(this.timer)
             },

             showgetcompra: function(item){

                 axios.get('/api/cart/'+item.id)
                .then((res)=>{

                    this.vercompra = res.data
                    console.log(res.data)
                })
                .catch((err)=>{
                    console.log(err)
                })
             },
             eliminarcompras(){

             }

        }

    }
</script>

    
asked by Wilmer Ramiro Cristancho Cruz 08.10.2018 в 18:24
source

1 answer

0

I have seen that you are doing a console.log of res.data , then the variable this.vercompra already has res.data

Here are two possibilities, since it is an object and not an array, you can not do the v-for.

  • Possibility:
  • If there is an array within Order:

    <div v-for="item in vercompra.Orden">
        <h1>hola {{item.Img_Produ}}</h1>
    </div>
    
  • Possibility:
  • <h1>hola {{vercompra.Orden["0"].Img_Produ}}</h1> <h1>hola {{vercompra.Pago}}</h1>

        
    answered by 08.10.2018 в 20:32