Laravel 6 如何将参数传递给 Vue Js @click 方法
Laravel 6 How to pass parameter to Vue Js @click method
我想传递一个参数给 Vue 组件。请帮忙
Blade
@extends("./layouts.app")
@section("title")
{{$shop->shop_name}}
@endsection
@section("content")
<addToCart></addToCart>
@endsection
Vue Js
<template>
<div class="button-container">
<button @click="addToCart(product_id)">Add To Cart</button>
</div>
</template>
您应该按照以下步骤访问 product_id
在您的 addToCart 组件中添加 product_id,如下所示:
@section("content")
<addToCart :product_id="$product_id"></addToCart>
@endsection
在您的组件中,您应该得到 :product_id
和 props array
,如下所示:
<template>
<div class="button-container">
<button @click="addToCart(product_id)">Add To Cart</button>
</div>
</template>
<script>
export default {
props: ["product_id"],
methods: {
addToCart(product_id) {
//code
}
}
</script>
注意:我想你有 product_id
并且你正确地完成了组件的其他部分。
在你的 Vue Js
添加新道具数组
<template>
<div class="button-container">
<button @click="addToCart(product_id)">Add To Cart</button>
</div>
</template>
<script>
export default {
props: ["product_id"],
methods: {
addToCart(product_id)
{
//code
}
}
</script>
在您的 Blade 添加:product_id ="product id",在 addToCart 组件中。
@extends("./layouts.app")
@section("title")
{{$shop->shop_name}}
@endsection
@section("content")
<addToCart :product_id="***product id goes here***"></addToCart>
@endsection
我想传递一个参数给 Vue 组件。请帮忙
Blade
@extends("./layouts.app")
@section("title")
{{$shop->shop_name}}
@endsection
@section("content")
<addToCart></addToCart>
@endsection
Vue Js
<template>
<div class="button-container">
<button @click="addToCart(product_id)">Add To Cart</button>
</div>
</template>
您应该按照以下步骤访问 product_id
在您的 addToCart 组件中添加 product_id,如下所示:
@section("content") <addToCart :product_id="$product_id"></addToCart> @endsection
在您的组件中,您应该得到
:product_id
和props array
,如下所示:<template> <div class="button-container"> <button @click="addToCart(product_id)">Add To Cart</button> </div> </template> <script> export default { props: ["product_id"], methods: { addToCart(product_id) { //code } } </script>
注意:我想你有 product_id
并且你正确地完成了组件的其他部分。
在你的 Vue Js 添加新道具数组
<template>
<div class="button-container">
<button @click="addToCart(product_id)">Add To Cart</button>
</div>
</template>
<script>
export default {
props: ["product_id"],
methods: {
addToCart(product_id)
{
//code
}
}
</script>
在您的 Blade 添加:product_id ="product id",在 addToCart 组件中。
@extends("./layouts.app")
@section("title")
{{$shop->shop_name}}
@endsection
@section("content")
<addToCart :product_id="***product id goes here***"></addToCart>
@endsection