What is the best way to create a constant, that can be accessible from entire application in VueJs ?

前端 未结 4 605
难免孤独
难免孤独 2021-01-17 16:43

I can create a constant through a store in my vuejs application, but i don\'t think it is a good practice.what is other way to do the same?

4条回答
  •  鱼传尺愫
    2021-01-17 17:17

    You can use the method

    const State= Object.freeze({ Active: 1, Inactive: 2 });
    export default {
      data() {
        return {
          State,
          state: State.Active
        };
      },
      methods: {
        method() {
          return state==State.Active;
        }
      }
    }
    

    or

    const State= Object.freeze({ Active: 1, Inactive: 2 });
    export default {
      data() {
        return {
          State_: State,
          state: State.Active
        };
      },
      methods: {
        method() {
          return state==State_.Active;
        }
      }
    }
    

提交回复
热议问题