1、页面按钮
<el-tag class="left-10px" effect="plain" type="danger" @click="Close(1)">电源1 /关</el-tag>
2、按钮事件
lvClose(id) {
this.$store.dispatch('command/closeDriverById', id).then(() => {
this.$message.success('关闭成功')
}
3、store中的actions中的函数
import { closeDriverById } from '@/api/command'
const actions = {
closeDriverById(store, id) {
return new Promise((resolve, reject) => {
closeDriverById(id).then(response => {
resolve(response.data)
}).catch(error => {
reject(error)
})
})
}
}
4、actions中导入的函数
export function closeDriverById(id) {
return request({
url: `/listen/driver/close/${id}`,
method: 'get'
})
}