当前位置:网站首页>Shangpinhui knowledge points of large e-commerce projects
Shangpinhui knowledge points of large e-commerce projects
2022-06-30 14:35:00 【tutou_ girl】
Secondary packaging axios
New folder api, Perform secondary encapsulation under this file 、 Unified interface management and other operations .
Unified interface management
Cross-domain problem
What is cross-domain ?
When the browser requests the resources of another domain name from the webpage of one domain name , domain name 、 port 、 The agreement is different , It's all cross domain
To solve the cross domain
1.JSONP
2.CROS
3. agent
Use webpack Agent provided ( In document proxy)
vue.config.js or webpack.config.js Middle configuration
module.exports = {
//...
devServer: {
proxy: {
// Carried by the current platform sending request /api, Request forwarding
'/api': 'http://localhost:9090',
},
},
};
Be careful : There should be before the back-end interface /api Otherwise, report 404
Add to blog If an invalid provider is found on the project, it will still report 404, It turned out blog The project is through webpack The initialization of the ( The launch project is npm run dev),config Under the folder index.js In file proxytable Empty label for , Cross domain configuration is available . Instead of creating vue.config.js File . And the interface is /login instead of /api/login.
VUEX
Data warehouse store, See another blog
VUEX-----store
Function anti shake and throttle
Shake proof : High frequency triggered events , Within the specified unit time , Only respond to the last , If triggered at the specified time , Then recalculate the time ( The events triggered later execute , Replaces the previous event )
// Submit form to add anti shake
SubmitFrom:_.debounce(function(){
this.$refs.ruleForm.validate((valid) => {
if (valid) {
var _this=this
console.log(this.$store.getters.getUser.user_id),
// Request from the back end , Submit data
newBlog(this.editForm,{
"Authorization": localStorage.getItem("token")})
.then(function (response){
if (response.data.data === true)
_this.tips()
_this.$router.push({
path:'/blogs'
})
})
} else {
console.log('error submit!!');
return false;
}
});
console.log('submit!');
},1000),
throttle : High frequency triggered events , Within the specified unit time , Only respond to the first time ( Before the execution of the previous trigger , Ignore subsequent events )
adopt js library lodash Provide encapsulated functions .
_.debounce(func, [wait=0], [options=]) Shake proof
_.throttle(func, [wait=0], [options=]) throttle
Optimize
Event delegation : Delegate the click event of the child element to the parent component .
<el-timeline>
<el-timeline-item :timestamp="blog.created" placement="top" v-for="blog in blogs" :key="blog">
<el-card>
<router-link :to="{name: 'BlogDetail', params: {blogId: blog.id}}">
<h4>{
{
blog.title}}</h4>
</router-link>
<p>{
{
blog.description}}</p>
</el-card>
</el-timeline-item>
</el-timeline>
v-for How many times does the loop have to be created routerlink Component instance of , Memory consumption may cause a stuck phenomenon . If programmed navigation is used , Every a Tags are bound to click event callback , The callback will also be executed repeatedly .
The event delegate is only executed once .
After event delegation :
Now click on the whole piece to jump , How to distinguish between clicked blogs .---------------- Use custom labels ( Must prefix with data-, And the hump will be automatically converted to lowercase , Be careful when deconstructing )
<div class="block" @click="toBlog">
<el-timeline>
<el-timeline-item :timestamp="blog.created" placement="top" v-for="blog in blogs" :key="blog">
<el-card>
<a>
<h4 :data-blogId="blog.id">{
{
blog.title}}</h4>
</a>
<p>{
{
blog.description}}</p>
</el-card>
</el-timeline-item>
</el-timeline>
</div>
toBlog(event){
let element=event.target;
//dataset Get custom tags , Deconstruct the custom tag value
let {
blogid}=element.dataset;
console.log(element.dataset)
this.$router.push({
name:'BlogDetail',
params:{
blogId:blogid
}
})
}
边栏推荐
- Querywrapper in mybaits plus
- 从控制层返回到js的json数据带“\”转译符,怎么去掉
- V3 02——What‘s new in Chrome extensions
- 【BUUCTF】 Have Fun
- remote: Support for password authentication was removed on August 13, 2021. Please use a personal ac
- 【BUUCTF】[GXYCTF2019]Ping Ping Ping1
- Go language mutex lock
- Lost connection to the flow server (0 retries remaining): |Out of retries, exiting! Error reporting solution (flow)
- PHP excel export function encapsulation (based on phpexcel class)
- Chapter 13 signal (III) - example demonstration
猜你喜欢

Shell programming overview

Computer screenshot how to cut the mouse in

2021 geek challenge Web

Error on datetime when importing SQL file from MySQL

Heavyweight: the domestic ide was released, developed by Alibaba, and is completely open source!

Detailed explanation of the first three passes of upload Labs

Zend studio how to import an existing project

The programming competition is coming! B station surrounding, senior members and other good gifts to you!

Wuenda 2022 machine learning special course evaluation is coming!

Geoffreyhinton: my 50 years of in-depth study and Research on mental skills
随机推荐
Error $(...) size is not a function
On simple code crawling Youdao translation_ 0's problem (to be solved)
Initial attack and defense world Misc
Upgrade composer self update
ot initialized – call ‘refresh’ before invoking lifecycle methods via the context: Root WebApplicati
【 scientific literature measurement 】 mining and visualization of keywords in foreign and Chinese Literature
Uniapp upload image method
Implementation of forwarding server using IO multiplexing
@Role of ResponseBody
Talk about Vue's two terminal diff algorithm, analysis of the rendering principle of the mobile terminal, and whether the database primary key must be self incremented? What scenarios do not suggest s
Je suis à Foshan, où puis - je ouvrir un compte? L'ouverture d'un compte par téléphone mobile est - elle sécurisée?
DB2 SQL Error: SQLCODE=-206, SQLSTATE=42703
I want to ask how to open an account at China Merchants Securities? Is it safe to open a stock account through the link
【BUUCTF】[GXYCTF2019]Ping Ping Ping1
中信期货开户麻烦吗安全吗,期货开户手续费是多少,能优惠吗
Three uses of golang underscores
Chapter 13 signal (III) - example demonstration
Is it troublesome for CITIC futures to open an account? Is it safe? How much is the handling charge for opening an account for futures? Can you offer a discount
Attack and defense world web questions
Effect of shadow around the block after mouse over