簡體   English   中英

通過數據刀片(laravel)來響應組件

[英]pass data blade (laravel) to react component

我需要在刀片中傳遞數據以響應組件。 我使用laravel 5.6。
例如在簡單的react組件中通過'props'傳遞數據,而我在laravel文檔中找不到要傳遞的方法。 我已經嘗試過(刀片):

<Preview article={{ $article }}></Preview>

反應:

constructor(props){
  super();
  this.state={
    article: props.article
  }
}

render() {
  return (
    <div>
      <h2>{this.state.article}</h2>
      <h3>Net</h3>
    </div>
  );
}

我如何在Laravel中做到這一點? 預先感謝您的幫助。

用這個 :

{!! $article !!}

代替這個:

{{ $article }}

要將blade數據傳遞給react ,只需在blade視圖中使用let即可。

將您的視圖更改為這樣

// Use react to display article
<Preview article={article}></Preview>

// Pass data to react
<script>
      let Article= '{{ $article }}'
</script>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM