How vue uses methods of classes

the class defined in a module then introduces the module in the entry file, but all vue components cannot be displayed. Cannot call a class as a function is our class file written correctly? Can I change it, everyone? What should I do if I want to use this validatePass method of the class in the vue component?

index.js

const base = class {
 validateContent (value) {
    let str = value.replace(/(^\s*)|(\s*$)/g, "")
    let strlen = str.length
    if (strlen > 500) {
      return ""
    } else if (strlen === 0) {
      return ""
    }
  }
}

export default base

Import index.js into the entry file

import Base from "./common/index.js"

Code of the Release component

<template>
  <div>
    <el-input type="textarea" v-model="msg" :rows="5" :autosize="{ minRows: 5, maxRows: 6}"></el-input>
    <button @click="release(555)">aaa</button>
  </div>
</template>

<script>
export default {
  name: "Release",
  data () {
    return {
      msg: ""
    }
  },
  methods: {
    release (str) {
      const base = new Base()
      console.log(base)
    }
  }
}
</script>

<style scoped>
</style>
Sep.24,2021

landlord, first of all, understand and understand what Vue.use () is used for and what parameters to receive. Here you can refer to the official document, portal .

so change it to Vue.use (new base ()) .

if you simply define a class and need a reference, the usage is actually very simple.

</a><br>:

class Func{
  validatePass (value) {
  },
  validateUser (value) {
  },
}
let getFunc = new Func();
export default getFunc;

//
import getFunc from './common/index.js'
//
getFunc.validatePass()
Menu