刚开始学习vuex,不能删除item。我可以直接在组件中删除项目。
deleteCar (cars, id) {
this.$http.delete('http://localhost:3000/cars/' + cars.id)
.then(() => {
this.cars.splice(id, 1)
})
}
Run Code Online (Sandbox Code Playgroud)
在 vuex 我有:
state: {
car: {},
cars: []
},
mutations: {
ADD_CAR (state, car) {
state.car = car
},
GET_CARS (state, cars) {
state.cars = cars
}
},
actions: {
createCar({commit}, car) {
axios.post('http://localhost:3000/cars', car)
.then(() => {
commit('ADD_CAR', car)
})
},
loadCars({commit}) {
axios.get('http://localhost:3000/cars')
.then(res => {
const cars = res.data
commit('GET_CARS', cars)
})
}
}
Run Code Online (Sandbox Code Playgroud)
我想删除项目的组件中的代码:
<div class="card mb-3" v-for="(car, i) in …
Run Code Online (Sandbox Code Playgroud)