0

I am very new to vue.js ,

I am using single file components with webpack , I am trying to calculate the sum of {{operating.totaloperating}}, I understand that to accomplish this I need to pass operating data back to script as prop, am I right? How can I do that? When I try to pass it as prop, it says undefined.

I can pass props to this component only from template, but not in the file itself.

<template>
    <tr v-for="operating in operatings" :operating="operating">
        <th scope="row">{{$index+1}}</th>
        <td>{{operating.name}}</td>
        <td>-</td>
        <td>{{operating.totaloperating}}</td>
    </tr>
</template>

<script>
    export default {
        props: ['operating'],
        data: function () {
            return {
                preloader: true,
                operatings: []
            }
        },

        methods: {

            fetchTotal: function () {
                this.$http.get('/api/totaloperating').then((response) => {
                    this.$set('operatings', response.json()),

                });
            }
        },



        ready: function () {

            this.fetchTotal()

        }
    }
</script>
7
  • What does response contain? Commented Aug 23, 2016 at 9:27
  • response contains an array [{"id":1,"totalsalary":"900"},{"id":2,"totalsalary":"100"}] , i want to reach total: 1000 . :operating="operating" this attribute not working inside of single file component . i returns undefined. Commented Aug 23, 2016 at 9:30
  • Then where is totaloperating??? Commented Aug 23, 2016 at 9:44
  • Sorry , i wrote wrong , its not totalsalary , the array is [{"id":1,"totaloperating":"900"},{"id":2,"totaloperating":"100"}] Commented Aug 23, 2016 at 9:48
  • 1
    Works to me jsfiddle.net/gurghet/dg32j4v0 Commented Aug 23, 2016 at 10:01

1 Answer 1

1

You should remove :operating="operating" from the tr since is not a component. Also the prop operating is of no use. Be sure to insert this component in a <tbody> or it won't work at all. What for errors in the console.

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

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.