简单小案例
效果图
实现
App.vue
<template>
<div>
<p>
<input type="text" v-model="text" />
<button @click="addGood">加购物车</button>
</p>
<ul>
<li v-for="(good, index) in goods" :key="good.id">
<span>{
{good.text}}</span>
<span>¥{
{good.price}}</span>
<button @click="addCart(index)">加购物车</button>
</li>
</ul>
<!-- 购物车 -->
<Cart :name="name"></Cart>
</div>
</template>
<script>
import Cart from "./components/Cart";
import axios from "axios";
export default {
data() {
return {
name: "购物车",
text: "",
cart: [],
goods: []
};
},
// 使用es7的async+await 语法
// async created() {
// // 使用axios获取接口数据
// // 查询产品列表
// try {
// const response = await axios.get("/api/goods");
// console.log(response);
// this.goods = r