Today, every front end is no stranger to Vue, and the Vue framework is one of the most Popular front-end frameworks, and its momentum is chasing react. I recently made a project with Vue, and here's what I've learned from it.There are a lot of documents for building projects with Vue+webpack now, and I'm not going to be too tired.Technology stack
vue2.0
Vue-router
Axios
Interception deviceFirst, we need to understand what the pur
successful login.Login intercept is this the end of the block? And not. This approach is simply a front-end routing control and does not really prevent users from accessing routes that require logon privileges. Another case is that the current token is invalid, but token is still stored locally. When you visit a route that requires login permissions, you should actually let the user log in again.At this point you need to combine the HTTP Interceptor + back-end interface returned by the HTTP sta
One, the use of routing interception Router.beforeeach (to, from, next) => { (to.meta.requireAuth) {// Determines whether the route requires logon rights if (store.state.token) {/ / next (); else {next { Path: '/login ' // route path as parameter, jump to the route after successful login }) }} else {next (); }})Second, the use of interceptorsTo handle all HTTP requests and responses uniformly, you need to use the Axio
Learning Vue and Nodejs process, involving the Axios, today in order to test, wrote Get and post two methods to interact with node server, the result because the header and parameters for a long time, in this record, while sharing;Because of the new contact Axios, in the test method, writing is very simple things, but can achieve the basic function, the great god see words. Guidance is very welcome.Get meth
Vue.js Learning cross-domain request agent and Axios: cross-domain Request proxy1: Open Config/index.jsmodule.exports{ Dev: { }}Find proxytable{} here, instead:Proxytable: { '/api ': { target: ' http://121.41.130.58:9090 ',//Set the interface domain name and port number you are calling do not forget to add the HTTP changeorigin: True, pathrewrite: { ' ^/api ': '//Here is understood to use '/api ' instead of the
Used Axios should be clear, get local JSON file is no problem, and on the other domain name down API interface will be error, because involved in cross-domain, then in vue-cli scaffolding, there is a simple way to deal with.Step one, open the Config folder Index.js, find proxytable: {}, modify the domain name of the interface you want.Step two, use Axios in the component.Step three, restart cnpm run Dev, th
/** First Step * Configure the switch between the compilation environment and the on-line environment * BASEURL: Domain name address * Routermode: Route mode * Imgbaseurl: The domain name where the picture is located **/Let Host= ' '; let Routermode= ' Hash ';//Let Imgbaseurl;if(Process.env.NODE_ENV = = ' development ') {Host= ' http://test.xxx.com ';//test Environment Host //imgbaseurl = ' http://cangdu.org:8001/img/'; If the picture needs to be placed on a third-party platform, you can chan
, sub-pages and secondary pages using a single-page form of items.Technology stack
es6+
Vue2.0
Vuex
Vue-router
Axios
Webpack4
Project Packaging Instructions
NPM module (vue, VUEX, etc.) packaged into a separate JS file
Common components and public functions packaged into a single JS file
Single-page and multi-page, are packaged according to the page, that is, each page component is packaged into a separate JS file
Solve the problem that the vue processes parameters in the axios post request, vueaxios
Many of my friends will definitely use axios requests when using vue, including axios, which is already included in vux, which is easy to use and clearly described in this document, however, when we use post for submission, we find that sometimes the parameters are not sent t
1. Static references2.NPM mode installation (recommended)$ npm Install Axios--save-save ==> is a dependencies node that adds package information to a Package.json that represents a package that is dependent on publishing. -save-dev ==> is a devdependencies node that adds package information to a Package.json and represents a package that is dependent on development.3. Eight APIs (details: Https://www.npmjs.com/package/axios1.axios.request (config)
The latest days to learn a little react, found a few problems, estimated new into the pit of the students will also encounter, the following I first listed what time1. Request Cross-domain issues2. How to initiate a request3. Simple package of AxiosGlobal installation of Create-react-app scaffolding to help us create a new react projectNPM install-g create-react-app Then create the REACT projectCreate-react-app XXX Project NameThen install dependencies, and run the React projectInstalling NPM In
Installing Axiosnpm install axios --saveCreate an instance (Utils/fetch.js)Axios default submission format is:application/jsonYou can use the QS module (required to install) to convert the submitted format toapplication/x-www-form-urlencodeddata => qs.stringify(data)you can submit a normal form by setting the Transformrequest propertyimport axios from 'axios'cons
Sorry, the following request of the link, I will hide the domain name, so want to try to find a friend trouble themselves for a new test, I'm sorry
Cross-domain is also configured below
1.config/index.js configuration: Troubleshooting cross-domain dev: {env:require ('./dev.env '), port:8008, Autoopenbrowser:false, Assetssubdirector Y: ' Static ', Assetspublicpath: '/', proxytable: {'/ajaxurl ': {target: ' https://www.aaaaaaa.com/', Changeo Rigin:true, Pathrewrite: {' ^/ajaxurl ': '/'}}} 2.main.
0--Project DescriptionNote that this project originates from a course network shopping cart tutorial, but in the development process, found in the development process or vue-resource (announced the non-updated class $.AJX () plug-in), for future development use Axios.js, details reference1 Initial static pagedelete Cancel Select allTotal:2 Cart.js/** * Created by Administrator on 2017/4/2 0002.*/Let Vmcart=NewVue ({el:' #app ', data: {productlist: []//as a product list}, filter: {//Local Filter
First, IntroductionLook at the profile of the official website:"Promise based HTTP client for the browser and node. js"HTTP request client based on Promise, which can be used in both the browser and node. js.Second, features:1, send xmlhttprequests request in the browser;2. Send HTTP requests in node. js;3, support Promise API;4, interception request and response;5, conversion request and response data;6. Automatic conversion of JSON data;7, the client supports the protection of security from XS
.
See the complete approach/src/router.js
Among them, to.meta we customize the data, including the fields we just defined requireAuth . Use this field to determine whether the route requires logon permissions. If required, the current app does not have tokens, then jump to the login page and sign in. Jump to destination route after successful login.Login intercept is this the end of the block? And not. This approach is simply a front-end routing control and does not really prevent
Refer to the code of this encapsulation API to understand the problem with basePlus an understanding of ' ${base/login} ' below encapsulates Axios request for invocation Let base = "Export Const Requestlogin = params + = {return Axios.post (' ${base}/login ', params). Then (res = res.data)}Export Const Reqsaveuserprofile = params + = {return Axios.post (' ${base}/user/profile ', params). Then (res = Res.dat A)}Export Const Reqgetuserlist = params +
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.