There are too many methods in the vue page methods, can you extract a method file?

there are more than 10 methods for methods in one of my .vue files, and this page looks messy.

is it because my componentization is not thorough enough;

is there any way to make the file more concise


1. Subdivide components
2. Extract the public method, and when using it, import comes in


I think it's safe to pull out a minxin.


that's what I did

//  
--page
+ index.vue
+ page.html
+ page.js
+ page.scss

// index.vue
<template src="./page.html"></template>
<script src="./page.js"></script>
<style scoped lang="scss"  src="./page.scss"></style>

// page.html
<div></div>

// page.js
export default {
  name: 'Page',
}

I don't like too many lines of code in a file, so divide it this way.
if a component has a small amount of code, it can be written in a file.
in addition, develop good coding habits and naming conventions. The code looks comfortable.


you can write a separate js file, put it in main, to become a public file, and insert it directly into methods


. I have a vue file with more than 600 lines of code.
I feel like I should try to subdivide components


write a public js, and introduce appropriate points


feel the same way as the students in the 600 lines above

at present, many pages are full of hundreds of lines. If you look at it again the next day, you will feel dizzy

.

the way to try or is
1, use Mixin, and then introduce, which effectively reduces the code
, but what is very sinister is that if someone else writes it, you have no idea which mixin file your referenced method is in. Find

one by one.

2. Try to use await, so that the code looks level

.

3. Separate functions that do not need this
for example, if a function only has console.log (123), then you can put this separately in the bottom of the page, or in another func.js file, and then import in
. The advantage is that, for the first way, I can know which function is in which file
. The downside is that you will be divided into many sub-functions
of course. Feel free to use .call or .apply if you don't recommend it

.

of course, it is best if it can be divided into subcomponents


an extremely complex component with more than 1200 lines of code. It is difficult to read the code too long, but when it is split into mixins, or put into an external file import, there is also a problem that it is too granular, and it is troublesome for others to find it. Sometimes I forget


after a long time.

there are more than 100 methods that need to be reconsidered.

the best way is to extract it into minxins

the this of minxins points to the vue instance that calls this minxins

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b31472-4030c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b31472-4030c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?