服务构建与前后端分离的开发

服务构建与前后端分离的开发

github链接为:github

任务

主要负责前端部分,前端框架选择VUE,主要有首页、注册页、登陆页、详情页组成

页面展示

首页

<template>
  <div id="app">
  <el-menu
    :router="true"
    :default-active="this.$route.path"
    class="header"
    mode="horizontal"
    @select="handleSelect"
    background-color="#545c64"
    text-color="#fff"
    active-text-color="#ffd04b">
    <el-menu-item index="/" >
      主页
    </el-menu-item>
    <el-menu-item index="/user" style='float:right' v-if="this.$store.state.username">
      {{ this.$store.state.username }}
    </el-menu-item>
    <div v-else="">
      <el-menu-item class = "log" index="/join" style='float:right'>注册</el-menu-item>
      <el-menu-item class = "log" index="/login" style='float:right'>登陆</el-menu-item>
    </div>
  </el-menu>
    <router-view/>
  </div>
</template>

在这里插入图片描述

登录页

<template>
  <div class="hello">
      <h1>{{ msg }}</h1>
      <div>
          <el-input v-model="userID" placeholder="用户名" class='input'></el-input>
      </div>
      <br>
      <div>
          <el-input v-model="password" placeholder="密码" class='input' type='password'></el-input>
      </div>
      <br>
      <div>
        <el-button type="primary" @click="cilckLogin()">登录</el-button>
      </div>
  </div>
</template>
cilckLogin: function () {
      var that = this
      this.$axios.request({
        url: 'http://localhost:8081/user/login',
        method: 'Post',
        data: JSON.stringify({
          Username: this.userID,
          Password: this.password
        }),
        responseType: 'json'
      }).then(function (response) {
        console.log(response.data)
        if (!response.data.error) {
          that.$store.commit('saveToken', {
            username: that.userID,
            token: response.data.ok
          })
          that.$router.push('/')
        } else {
          alert(response.data.error)
        }
      })
    }

在这里插入图片描述

注册页

<template>
  <div class="hello">
    <h1>{{ msg }}</h1>
  <div>
      <el-input v-model="userID" placeholder="用户名" class='input'></el-input>
   </div>
   <br>
   <div>
      <el-input v-model="password" placeholder="密码" class='input' type='password'></el-input>
   </div>
   <br>
   <div>
      <el-input v-model="mail" placeholder="邮箱" class='input'></el-input>
   </div>
   <br>
   <div>
    <el-button type="primary" @click='clickJoin()'>注册</el-button>
  </div>
  </div>
</template>
clickJoin: function () {
      var that = this
      this.$axios.request({
        url: 'http://localhost:8081/user/register',
        method: 'Post',
        data: JSON.stringify({
          Username: this.userID,
          Password: this.password
        }),
        responseType: 'json'
      }).then(function (response) {
        console.log(response.data)
        if (response.data.ok) {
          that.$store.commit('saveToken', {
            username: that.userID,
            token: response.data.ok
          })
          that.$router.push('/')
        } else {
          alert(response.data.error)
        }
      })
    }

在这里插入图片描述

详情页

<template>
  <div class="main">
    <div class = "title">
      <h2>{{ article.title }}</h2>
    </div>
    <div class = "extra">
      <div class="date">{{article.date}}</div>
      <div class="author">{{article.username}}</div>
    </div>
    <div class = "content" v-html="article.content"></div>
    <div class = "comments">
      <div class="addComment">
        <el-input v-model="commentadd" class='inputClass'></el-input>
        <el-button type="primary" size="mini" @click="DoComment()">评论</el-button>
      </div>
      <ul>
        <li v-for="item in article.comments" :key="item">
          <div class="header">
            <div class="author">{{item.user}}</div>
          </div>
          <div class = "comment">{{item.content}}</div>
        </li>
      </ul>
    </div>
  </div>
</template>
init: function () {
      var that = this
      var nid = this.$route.params.id// 获取id
      this.$axios.request({
        url: 'http://localhost:8081/article/' + nid,
        method: 'GET',
        responseType: 'json'
      }).then(function (response) {
        console.log(response.data)
        that.article = response.data.ok
      })
    }

在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值