首页 > 其他分享 >vue+go实现注册功能

vue+go实现注册功能

时间:2023-12-26 21:12:49浏览次数:37  
标签:username vue http phone json 注册 go password border

<!DOCTYPE html>
<html>
<head>
<meta charset="utf8">
<style>
.container {
width: 400px;
margin: 0 auto;
padding: 20px;
border: 1px solid #ccc;
border-radius: 5px;
background-color: #f5f5f5;
}

h1 {
text-align: center;
margin-bottom: 20px;
}

.form-group {
margin-bottom: 15px;
}

label {
display: block;
margin-bottom: 5px;
}

input[type="text"],
input[type="password"],
input[type="tel"] {
width: 100%;
padding: 8px;
border: 1px solid #ccc;
border-radius: 4px;
}

button {
display: block;
width: 100%;
padding: 10px;
border: none;
border-radius: 4px;
background-color: #4CAF50;
color: #fff;
font-size: 16px;
cursor: pointer;
}

button:hover {
background-color: #45a049;
}
</style>
</head>
<body>
<div id="app">
<div class="container">
<form id="registration-form" @submit.prevent="submitForm">
<h1>用户注册</h1>
<div class="form-group">
<label for="username">用户名:</label>
<input type="text" id="username" name="username" v-model="username" placeholder="Enter your username" required>
</div>
<div class="form-group">
<label for="password">密码:</label>
<input type="password" id="password" name="password" v-model="password" placeholder="Enter your password" required>
</div>
<div class="form-group">
<label for="phone">手机号:</label>
<input type="tel" id="phone" name="phone" v-model="phone" placeholder="Enter your phone number" required>
</div>
<button type="submit">点击注册</button>
</form>
</div>
</div>
</body>
</html>

<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/axios.min.js"></script>
<script>
new Vue({
el: '#app',
data: {
username: '',
password: '',
phone: ''
},
methods: {
submitForm() {
// 使用 Axios 发送 GET 请求
axios({
method: "post",//请求方法
params: {
username: this.username,//请求参数
password: this.password,//请求参数
phone:this.phone
},
url: "http://localhost:8080/users/register",
}).then(res => {
if(res.data.code == 200) {
alert(res.data.message);
window.location.href = "list.html"
}else{
alert(res.data.message);
}
})
}
}
});
</script>

package main

import (
"encoding/json"
"fmt"
"gorm.io/driver/mysql"
"gorm.io/gorm"
"net/http"
)

type Users struct {
Id int `json:"id"`
Username string `json:"username"`
Password string `json:"password"`
Phone string `json:"phone"`
}

func Register(w http.ResponseWriter, r *http.Request) {

// 设置允许跨域的域名
w.Header().Set("Access-Control-Allow-Origin", "*")
// 初始化数据库连接
dsn := "root:root@tcp(127.0.0.1:8889)/2112a"
db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{})
if err != nil {
fmt.Println("连接失败")
return
}

username := r.FormValue("username")
password := r.FormValue("password")
phone := r.FormValue("phone")
user := Users{
Username: username,
Password: password,
Phone: phone,
}
err = db.Create(&user).Error
if err != nil {
response := map[string]interface{}{"code": 500, "message": "添加失败"}
json.NewEncoder(w).Encode(response)
} else {
response := map[string]interface{}{"code": 200, "message": "添加成功"}
json.NewEncoder(w).Encode(response)
}

}
func main() {
http.HandleFunc("/users/register", Register)
http.ListenAndServe("localhost:8080", nil)
}



标签:username,vue,http,phone,json,注册,go,password,border
From: https://www.cnblogs.com/superzwb/p/17929356.html

相关文章

  • MagicArray:像php一样,让Go业务代码不再卷!
    卷!一个字形容了当今码农行业的现状。一层一层的代码结构,一个一个dto,entity,vo,req,resp。这些对象越来越多,让码农们非常劳于奔命,加一个字段,改一个字段,影响面有多少。代码量也越来越大。有可能一个代码,要建10多个数据对象。这虽然有点夸张,但体现了行业的乱象。我是曾经写php代码的......
  • [资源管理] SQL Server 通过Resouce Governor来限制用户资源的使用
    创建资源池CREATERESOURCEPOOL[rp_test]WITH(min_cpu_percent=0,max_cpu_percent=1,min_memory_percent=0,max_memory_percent=1,AFFINITYSCHEDULER=AUTO)GO创建负载组CREATEWORKLOADGROUP[wlp_test]WITH(group_max_requests=10,importance=High,request_m......
  • Vue3+TS+Vite中 vConsole 插件的使用
    vConsole一个轻量、可拓展、针对手机网页的前端开发者调试面板。vConsole是框架无关的,可以在Vue、React或其他任何框架中使用。现在vConsole是微信小程序的官方调试工具。https://gitee.com/Tencent/vConsole/ 平时在web应用开发过程中,我们可以console.log去输出一些......
  • mongodb安装
    #!/bin/bash###############################################################FileName:install_redis.sh#Version:V1.0#Author:junwang#Organization:#CreatedTime:2021-04-1417:12:54#Description:###############################################......
  • mongo升级服务,数据迁移迁移
    3*升级到5.*,会碰到索引不兼容问题 usestars_salesvarcollections=db.getCollectionNames();collections.forEach(function(collection){varindexes=db[collection].getIndexes();print("Indexesforcollection"+collection+":");printjson(......
  • ArgoCD 添加私有仓库
    HTTPS方式访问私有仓库ArgoCDCLI添加私有仓库#argocdrepoaddhttps://github.com/argoproj/argocd-example-apps--username<username>--password<password>dashboard添加私有仓库SSHPrivateKeyCredentialArgoCDCLI添加known_hosts#ssh-keyscan-p35022192.168......
  • ArgoCD notifications 配置
    ArgoCDnotifications TriggersTriggers定义应发送通知的条件。定义包括名称、条件和通知模板参考。条件是一个谓词表达式,如果通知则返回true应该发送。Triggers列表1.on-created#Application创建2.on-deleted#Applic......
  • ArgoCD和Argo Rollouts自动化部署应用
    环境说明使用ArgoRollouts部署nginx应用:1.使用Rollout部署nginx2.采用canary部署策略3.结合Analysis进行渐进式交付4.结合IstioVirtualService进行自动化流量分割和流量迁移5.部署清单放在gitrepo中使用ArgoCD进行自动化部署:1.使用Application监视GitRepository2......
  • ArgoCD 添加私有仓库
    HTTPS方式访问私有仓库ArgoCDCLI添加私有仓库#argocdrepoaddhttps://github.com/argoproj/argocd-example-apps--username<username>--password<password>dashboard添加私有仓库SSHPrivateKeyCredentialArgoCDCLI添加known_hosts#ssh-keyscan-p35022192.168......
  • Argo Rollouts TrafficRouting结合Istio进行Canary流量管理基础
    ArgoRolloutsTrafficRouting概述流量治理技术实现如下:1.按百分比进行流量管理(即5%的流量应流向新版本,其余流量流向稳定版本)2.基于标头的路由(即将带有特定标头的请求发送到新版本)3.镜像流量,其中所有流量都被复制并并行发送到新版本(但响应被忽略)TrafficRouting配置apiVersi......