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
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
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
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
Previous: The second parameter of pushState is invalid
Next: Input file uploads multiple-choice images, traverses the fles push array, but cannot get the array.
when namespaced is not used, actions is registered globally by default, but after use, actions will become under the module, but I don t want to do this. I also want it to be global. My namespace:true is just for the convenience that I introduce state, ...
I want a variable in the drop-down box v-model data, and the default value of this variable is the constant defined in state, but what if it doesn t change with the value in state? reference: https: codeshelper.com q 10. The value of computed canno...