【vuejs】用vue写一个自己的博客管理系统(一):前期准备

最开始,我用过wordpress搭建了自己的博客。
后来,我也用过gitpage+hexo搭建的一个小小的博客

虽然后面都没有用,只是偶尔登上去看看。
现在为了锻炼锻炼自己的水平,决定自己用vue+express搭建一个属于自己的博客管理系统。

配置环境。

  1. 安装node.js和npm。
    在官网选择适合自己电脑的安装包,然后一直next,直到安装完成。打开命令行,输入node -v就能看到node的版本,同理npm -v可以查看npm的版本,如果npm等级过低,直接npm install -g就行了。
  2. 使用淘宝镜像。
    因为npm官方镜像非常的慢,所以在这里,可以选择使用淘宝的镜像。
    $ npm  install  -g  cnpm  --registry=https://registry.npm.taobao.org
    
    安装好以后,就可以使用cnpm安装其他的模块了。
  3. 安装vue-cli脚手架
    cnpm install vue-cli -g      //全局安装 vue-cli
    
    以上版本是2.x的版本,现在vue-cli脚手架已经升到了3.x,而3.x版本更为的简洁,所以我们可以安装3.x的版本。
    npm install @vue/cli -g
    
    安装完成之后,在命令行里输入vue -V查看一下版本,
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
好的,我可以为您提供一个简单的学生信息管理系统的示例,使用Spring Boot和Vuejs前端框架。以下是实现步骤: 1. 创建Spring Boot项目 使用Spring Initializr创建一个新的Spring Boot项目。在“Dependencies”选项卡中添加以下依赖项: - Spring Web - Spring Data JPA - H2 Database - Lombok 2. 创建实体类 创建一个名为“Student”的实体类,该类包含以下属性:id、姓名、年龄、性别和成绩。 ```java @Entity @Data @NoArgsConstructor @AllArgsConstructor public class Student { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; private String name; private Integer age; private String gender; private Double score; } ``` 3. 创建JPA Repository 创建一个名为“StudentRepository”的JPA存储库,用于与数据库交互。 ```java @Repository public interface StudentRepository extends JpaRepository<Student, Long> { } ``` 4. 创建REST控制器 创建一个名为“StudentController”的REST控制器,用于处理来自前端的HTTP请求。 ```java @RestController @RequestMapping("/api/students") @AllArgsConstructor public class StudentController { private final StudentRepository studentRepository; @GetMapping public List<Student> getAllStudents() { return studentRepository.findAll(); } @PostMapping public void addStudent(@RequestBody Student student) { studentRepository.save(student); } @PutMapping("/{id}") public void updateStudent(@PathVariable Long id, @RequestBody Student student) { Student existingStudent = studentRepository.findById(id).orElseThrow(() -> new EntityNotFoundException("Student not found")); existingStudent.setName(student.getName()); existingStudent.setAge(student.getAge()); existingStudent.setGender(student.getGender()); existingStudent.setScore(student.getScore()); studentRepository.save(existingStudent); } @DeleteMapping("/{id}") public void deleteStudent(@PathVariable Long id) { studentRepository.deleteById(id); } } ``` 5. 创建Vuejs前端 创建一个名为“StudentList.vue”的Vuejs组件,用于显示学生列表和添加/编辑/删除学生。 ```vue <template> <div> <h1>学生信息管理系统</h1> <table> <thead> <tr> <th>ID</th> <th>姓名</th> <th>年龄</th> <th>性别</th> <th>成绩</th> <th>操作</th> </tr> </thead> <tbody> <tr v-for="student in students" :key="student.id"> <td>{{ student.id }}</td> <td>{{ student.name }}</td> <td>{{ student.age }}</td> <td>{{ student.gender }}</td> <td>{{ student.score }}</td> <td> <button @click="editStudent(student)">编辑</button> <button @click="deleteStudent(student)">删除</button> </td> </tr> </tbody> </table> <div> <h2>{{ isNewStudent ? '添加学生' : '编辑学生' }}</h2> <form @submit.prevent="submitForm"> <label>姓名:</label> <input type="text" v-model="form.name" required> <br> <label>年龄:</label> <input type="number" v-model="form.age" required> <br> <label>性别:</label> <select v-model="form.gender" required> <option value="男">男</option> <option value="女">女</option> </select> <br> <label>成绩:</label> <input type="number" v-model="form.score" required> <br> <button type="submit">{{ isNewStudent ? '添加' : '保存' }}</button> <button type="button" @click="cancelForm">取消</button> </form> </div> </div> </template> <script> import axios from 'axios'; export default { data() { return { students: [], form: { name: '', age: '', gender: '', score: '' }, isNewStudent: true } }, mounted() { this.fetchStudents(); }, methods: { fetchStudents() { axios.get('/api/students') .then(response => { this.students = response.data; }) .catch(error => { console.log(error); }); }, editStudent(student) { this.form = Object.assign({}, student); this.isNewStudent = false; }, deleteStudent(student) { axios.delete(`/api/students/${student.id}`) .then(response => { this.students = this.students.filter(s => s.id !== student.id); }) .catch(error => { console.log(error); }); }, submitForm() { if (this.isNewStudent) { axios.post('/api/students', this.form) .then(response => { this.students.push(response.data); this.form = { name: '', age: '', gender: '', score: '' }; }) .catch(error => { console.log(error); }); } else { axios.put(`/api/students/${this.form.id}`, this.form) .then(response => { const index = this.students.findIndex(s => s.id === this.form.id); this.students.splice(index, 1, response.data); this.form = { name: '', age: '', gender: '', score: '' }; this.isNewStudent = true; }) .catch(error => { console.log(error); }); } }, cancelForm() { this.form = { name: '', age: '', gender: '', score: '' }; this.isNewStudent = true; } } } </script> ``` 6. 运行应用程序 启动Spring Boot应用程序并访问http://localhost:8080/。您应该能够看到一个包含学生列表的页面,您可以添加,编辑和删除学生。 以上就是一个简单的学生信息管理系统的示例,使用Spring Boot和Vuejs前端框架。希望对您有所帮助!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

萌村村花杨小花

谢谢大佬!!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值