This article example shares the specific code of vue+tp5 to implement a simple login function for your reference. The specific content is as follows Preparation: Install vue-cli, element-ui, as shown in package.json, just follow the installation 1. Create a views page in the src directory 2. Write in /src/router/index.js: import Vue from 'vue' import Router from 'vue-router' import HelloWorld from '@/components/HelloWorld' import login from '@/views/login/index.vue' Vue.use(Router) export default new Router({ routes: [ { path: '/', name: 'HelloWorld', component: HelloWorld }, { path: '/login', component: login } ] }) 3. Restore app.vue to the following figure: 4. Start writing code in /src/views/login/index.vue (find a login template): <template> <div id="app-1"> <div class="content"> <div class="content_input"> <div class="title"> <p>Administrator login</p> </div> <el-input v-model="UserName" clearable placeholder="Username"></el-input> <el-input v-model="PassWord" clearable show-password placeholder="Password"></el-input> <div class="content_button"> <el-button type="primary" @click="SignIn">Login</el-button> </div> </div> </div> </div> </template> <script> import '@/assets/css/style.css' const axios = require('axios') export default { name: 'Login', data () { return { UserName: '', PassWord: '' } }, methods: { SignIn () { let that = this let username = that.UserName let password = that.PassWord if (!username) { this.$notify.error({ title: 'Error', message: 'Username cannot be empty' }); return false } else if (!password) { this.$notify.error({ title: 'Error', message: 'The password cannot be empty' }) return false } else { // Pass the information to the backend for processing axios.post('/api/login/doLogin', { name: username, psw: password }) .then(function (response) { console.log(response) }) .catch(function (error) { console.log(error) }) } } } } </script> 5. Set proxytable in config/index.js and use axios for cross-domain requests proxyTable: { '/api/*': { // api is a proxy interface target: 'http://localhost:8085/index.php/index', // Here I proxy to the local service changeOrigin: true, pathRewrite: { // This is to append a link. For example, if the interface really contains /api, this configuration is required. '^/api': '/', // and the following two ways of writing, it varies according to different people's needs. // Equivalent to /api + /api == http://localhost:54321/api // If written as '^/api': '/' // Equivalent to /api + / == http://localhost:54321/ // /api here == http://localhost:54321 } } }, 6. /src/main.js // The Vue build version to load with the `import` command // (runtime-only or standalone) has been set in webpack.base.conf with an alias. import Vue from 'vue' import App from './App' import Router from 'vue-router' import router from './router' import axios from 'axios' import ElementUI from 'element-ui' import 'element-ui/lib/theme-chalk/index.css' import 'font-awesome/css/font-awesome.min.css' Vue.use(ElementUI) Vue.use(Router) Vue.config.productionTip = false Vue.prototype.$axios = axios /* eslint-disable no-new */ new Vue({ el: '#app', router, components: { App }, template: '<App/>' }) 7.In index/controller/Login.php in tp5 backend: <?php /** * Created by PhpStorm. * User: mx1 * Date: 2021/11/9 * Time: 15:21 */ namespace app\index\controller; use think\Controller; class Login extends Controller { public function doLogin(){ $name=input('post.name'); $psw=input('post.psw'); return json([$name,$psw]); } } Note: If the proxytable you set does not work, verify that the interface is correct, then find the project directory in cmd and run: npm run dev Effect: The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: HTML embedded in WMP compatible with Chrome and IE detailed introduction
>>: 9 ways to show and hide CSS elements
Since the entire application needs to be deployed...
First, you need to determine which fields or fiel...
In some scenarios, we need to modify our varchar ...
This article shares the specific code of jQuery t...
FIFO communication (first in first out) FIFO name...
01. Command Overview dirname - strip non-director...
I have just come into contact with and become fam...
Preface When we use query statements, we often ne...
Compared with vue2, vue3 has an additional concep...
add -it docker run -it -name test -d nginx:latest...
Preface In daily development, we often encounter ...
This article uses examples to illustrate the basi...
Routing configuration commands under Linux 1. Add...
Table of contents Preface 1. The database name or...
This article shares a blinds special effect imple...