首页 > 解决方案 > 如何在Vue中的另一个函数的计算中使用函数返回值

问题描述

我在 Vue 中使用 laravel,并且刀片文件中有一个函数 updateTds,它返回接收到的 TDS,因此我需要使用 updateTds 函数中该文件模型中定义的函数的返回值来计算 TDS在那个数量上,但我不知道如何实现,有人可以帮助我理解吗?

This is the function in model file:
 public function Amount()
    {
        $country = optional($this->client)->country;
        $amount = $this->amount;

        if ($this->client->type == 'indian') {
            $amount = $this->amount + $this->gst;
        }

        return $amount . ' ' . optional($country)->currency_symbol;
    } ```

and this is in view file(blade file):

 @section('js_scripts')
<script>
    new Vue({
    el:'#form',

    methods: {
         updateTds() {
            this.tds = this.amount - this.amount_paid
            this.tds_percentage = (this.tds/this.amount) * 100
        },
    },

我想在 updateTds() 函数中使用从 Amount() 函数返回的金额。

Something like that:

 updateTds() {
            this.tds = this.amount(returned from Amount()) - this.amount_paid
            this.tds_percentage = (this.tds/this.amount) * 100
        },

感谢您的帮助并花时间帮助一个好奇但真正的 Vue 新手。

标签: javascriptvue.jslaravel-8

解决方案


推荐阅读