Skip to content

vue教程里的暴露是什么意思? #7029

Answered by bbcvc
cscsb asked this question in Help/Questions
Discussion options

You must be logged in to vote

使用expose函数来控制组件被ref时向外暴露的对象内容,借此来维护组件的封装性。

可以近似的它理解为 React函数组件 中的 useImperativeHandle
子组件可以使用useImperativeHandle可以让父组件输出任意数据

vuejs.org官网的例子👇

// 组件A
export default {
  // 只有 `publicMethod` 在公共实例上可用
  expose: ['publicMethod'],
  methods: {
    publicMethod() {
      // ...
    },
    privateMethod() {
      // ...
    }
  }
}

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by edison1105
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants