addContent.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <style lang="scss">
  2. .addclass {
  3. .el-input,
  4. button {
  5. width: 500px;
  6. }
  7. }
  8. </style>
  9. <template>
  10. <section class="addclass">
  11. <p>内容管理 > 栏目管理 > 新增栏目</p>
  12. <div class="content">
  13. <el-form label-width="80px">
  14. <el-form-item label="栏目名称">
  15. <el-input placeholder="栏目名称" v-model="form.name"></el-input>
  16. </el-form-item>
  17. <el-form-item label="排序字段">
  18. <el-input placeholder="排序字段" v-model="form.order"></el-input>
  19. </el-form-item>
  20. <el-form-item label=" ">
  21. <el-button @click="save" type="primary">保存</el-button>
  22. </el-form-item>
  23. </el-form>
  24. </div>
  25. </section>
  26. </template>
  27. <script>
  28. export default {
  29. components: {},
  30. data() {
  31. return {
  32. form: { name: "" }
  33. };
  34. },
  35. methods: {
  36. getData() {
  37. this.$api.getContentById({ id: this.form.id }).then(res => {
  38. this.form = res.data.data;
  39. });
  40. },
  41. save() {
  42. var parm = this.form;
  43. if (parm.id) {
  44. this.$api.editContent(parm).then(res => {
  45. if (res.data.code == 0) {
  46. this.$message({ message: "修改成功!", type: "success" });
  47. this.$router.push({ path: "/content" });
  48. } else {
  49. this.$message.error(res.data.message);
  50. }
  51. });
  52. } else {
  53. this.$api.addContent(parm).then(res => {
  54. if (res.data.code == 0) {
  55. this.$message({ message: "添加成功!", type: "success" });
  56. this.$router.push({ path: "/content" });
  57. } else {
  58. this.$message.error(res.data.message);
  59. }
  60. });
  61. }
  62. }
  63. },
  64. created() {
  65. if (this.$route.query.id) {
  66. this.form.id = this.$route.query.id;
  67. this.id = this.$route.query.id;
  68. this.getData();
  69. }
  70. }
  71. };
  72. </script>