最簡單粗暴新增公告功能
首先確定添加的頁面爲index.html
關鍵代碼
<!-- 公告--> <el-table :data="tableData" style="width: 100%" > <el-table-column :sort-method="tableSortBy('prop_ShowCon')" sortable label="公告"> <template slot-scope="scope"> <atx-edit-inline :readonly="!user.admin" :value="scope.row.prop_ShowCon" @change="updateShow(scope.row.udid, $event)"> </atx-edit-inline> </template> </el-table-column> </el-table>
Script代碼:
updateShow(udid, text) { // admin required $.ajax({ url: "/api/v1/devices/" + udid + "/properties", method: "put", contentType: "application/json", data: JSON.stringify({ "ShowCon": text, }) }).fail(ret => { if (ret.status == 400) { this.$message.error(ret.responseJSON.description) } else { this.$message.error(ret.responseText) } }) },
此方法是用表格顯示數據,當然可以換成其他組件;
在要添加的位置先增加html代碼,把script放到相應位置即可