How to suppress “Undefined” errors before fetching data in Vue

前端 未结 3 725
时光说笑
时光说笑 2021-01-24 03:54

I have a simple page where I display some data that are fetched from the server.

Template:

Order\'s customer name: {{ order.customer.name }}<

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-24 04:39

    I think you can test for order.customer :

    {{ order.customer && order.customer.name }}
    

    if order.customer is not defined, the expression evaluation will simply stop at the first term without throwing an error.

提交回复
热议问题