xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

Vue components props order All In One

Vue components props order All In One

vue template / vue component options order

Vue 组件参数顺序

按照一般情况下修改频率的大小,从上到下的顺序,统一组件的字段的结构,方便快速查找对应的类型,提高后续开发效率,避免一个组件出现多个 watch 类似情况的发生;

// 反例 ❌ 
/*
1. 没有组件名称
2. 随意组织 vue 组件参数字段的顺序
3. 存在重复的组件参数字段
4. 组件私有样式不使用 scoped
5. 存在没有使用的组件或库
*/

<template>
    <div class="conatiner-class">
      ...
    </div>
</template>

<script>
import _ from 'lodash';
import SearchSelect from './SearchSelect';

export default {
    // 1. 没有组件名称
    data () {
        return {
            //
        };
    },
    props: {
        //
    },
    watch: {},
    methods: {
     // 方法...
    },
    computed: {}, 
    mounted () {},
    destroyed () {},
    watch: {
      // 重复组件参数
    }, 
    components: {
        // SearchSelect,
    },
};
</script>

<style lang="scss">
// 4. 组件私有样式不使用 scoped
</style>

<style lang="scss">
// 全局样式
</style>

// 正例 ✅  
/*
1. 有唯一组件名称
2. 按照一定规则组织 vue 组件参数字段的顺序 (按照一般情况下修改频率的大小,从上到下的顺序)
3. 不存在重复的组件参数字段
4. 组件私有样式使用 scoped
5. 不存在没有使用的组件或库
*/

<template>
    <div class="conatiner-class">
      ...
    </div>
</template>

<script>
// import _ from 'lodash';
// import SearchSelect from './SearchSelect';

export default {
    name: 'CreativeSearcher',
    components: {
        // SearchSelect,
    },
    props: {
        //
    }, 
    data () {
        return {
            //
        };
    }, 
    computed: {}, 
    watch: {},
    mounted () {},
    destroyed () {},
    methods: {
     // 方法一般代码最多,放到最后...
    },
};
</script>

<style lang="scss" scoped>
// 组件私有样式使用 scoped
</style>

refs

vue & order of properties in components

https://eslint.vuejs.org/rules/order-in-components.html

https://vuejs.org/v2/style-guide/#Component-instance-options-order-recommended

https://v3.vuejs.org/style-guide/#component-instance-options-order-recommended



©xgqfrms 2012-2025

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @   xgqfrms  阅读(73)  评论(5编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2020-11-07 微服务架构
2020-11-07 React Query & SWR All In One
2020-11-07 Prometheus Monitoring Solution
2020-11-07 React Slingshot
2020-11-07 MathJax TeX & LaTeX All In One
2019-11-07 vscode & peacock extension All In One
2018-11-07 mogodb gui
点击右上角即可分享
微信分享提示