2017-10-07 9 views
0

ジョブが実行されている場合は、ボタンを無効にしたいと考えています。私はビューに渡されているコントローラのボタン状態を持っています。Vue JS無効ボタンaria-disable

public function index() 
    { 
     $orders = Order::orderBy('order_created', 'asc')->get(); 

     $buttonState = Sync::where('status', 'running')->exists(); 

     return view('orders.index', compact('orders', 'buttonState')); 
    } 

ビュー

<sync-button :active="{{ $buttonState }}"></sync-button> 

VueのJS

<template> 
    <button class="btn btn-primary" style="margin:5px;" 
    :disabled="disabledComputedProp" :aria-disabled="disabledComputedProp" 
    @click="sync">Sync Orders</button> 
</template> 

<script> 
    export default { 
     props: ['active'], 
     computed: { 
      disabledComputedProp() { 
       return this.active ? true : false; 
      } 
     }, 
     methods: { 
      sync() { 
       this.active = ! this.active; 

      } 
     } 
    } 
</script> 

[Vue warn]: Failed to generate render function: 

SyntaxError: Unexpected token } in 

コントローラ - 状態が真であるが、それが偽のとき、私は次のエラーを取得する際にコードが動作します

+1

'boolean'または 'string'である' active 'の値は何ですか? –

+0

これはboolen型です... $ buttonStateは真または偽ですboolean – rbur0425

+0

'アクティブな' 'props 'の値をバインドする必要がある属性に向けてください。私は計算されたプロパティでそれを設定する必要はないと思う –

答えて

0

Laravelを使用している場合は、Vue JSとbooleanです。ブール値は、vueに渡すためにJSONエンコードされている必要があります。

<sync-button :active="{{ json_encode($buttonState) }}"></sync-button> 

にビューを変更すると、エラーを修正しました。