我是一個初學者,我正在用 Vue 和 Laravel 構建一個專案,并有以下代碼:
<div class="preview-icon" @click="showPreview(product, 'heritage/' product.link.toLowerCase())">
<i class="material-icons"></i>
</div>
showPreview (product, link) {
this.preview.name = product.name;
this.preview.category = product.category;
this.preview.description = product.description;
this.preview.image = product.image;
this.preview.link = link;
this.preview.weight = product.weight;
this.preview.dimensions = product.dimensions;
this.preview.bulbs = product.bulbs;
console.log(link);
// Show Modal Response
$("#modal-preview").appendTo("body").modal('show');
}
product 引數是一個物件,這是出現在 console.log(product) 中的內容:
{
"id": 227,
"ul": 0,
"new": 1,
"category": "Suspension",
"productCategory": "suspension",
"description": "Inspired by the enigmatic life of Abbey Lincoln, this majestic pendant light will be the right lighting design choice for a dramatic dining room. A memorable piece that counts with golden finishes and black matte to give it a twist. This luxurious modern pendant lamp will be giving life and a statement to your modern home decor.",
"name": "ABBEY",
"weight": "Approx.: 15 kg | 33 lbs",
"dimensions": "Height: 11.8'' | 30 cm </br> Width: 43,3'' | 110 cm </br> Length: 74'' | 190 cm",
"bulbs": "6 x E14 Halogen | Max 28w",
"image": "thumbnail/products/227/abbey-suspension98b87227e8352440cd7d9a6e888aa113.png",
"image_hover": "thumbnail/products/227/abbey-suspension.jpg",
"imageAlt": "mid-century style, mid-century lighting, mid-century lighitng brand, mid-century modern lighting, mid-century modern, mid-century lighting fixture, mid-century fixture, mid-century modern fix",
"link": "Suspension/ABBEY",
"shop_url": "https://shop.delightfull.eu/abbey-suspension-light?utm_source=website&utm_medium=pagproduct&utm_content=delightfull-buy-now&utm_campaign=shop"
}
每次,產品物件都被插入資料庫資料,但現在我必須手動插入一些特定物件作為引數,但是如果我嘗試將物件直接插入到事件處理程式中,它會顯示一個錯誤:

那么是否可以將物件作為引數傳遞?
uj5u.com熱心網友回復:
是的,您可以并且對于其中的字串使用單引號,因為您""在事件處理程式中使用:
@click="showPreview({id:1,name:'test'})"
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/349217.html
標籤:javascript 拉拉维尔 Vue.js 目的
