Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setup 能够支持返回模板数据&渲染函数 #3521

Closed
chen-designs opened this issue Apr 1, 2021 · 1 comment
Closed

setup 能够支持返回模板数据&渲染函数 #3521

chen-designs opened this issue Apr 1, 2021 · 1 comment

Comments

@chen-designs
Copy link

What problem does this feature solve?

开发组件库时组件内部处理逻辑对外暴露容易对使用者带来困扰,希望能提供类似组件内部私有数据和方法如下:

export default Btn {
name: 'Bth',

setup(props){
    // 内部数据 & 方法, 不对外部访问
    const bth = ref(null)
    const handlerClick = e => {
        // 在出发点击事件前做点什么
        props.onClick(e)
    }

    // 公共数据 & 方法对外部公开
    const click = () => btn.value.click()
    const focus = () => btn.value.focus()

    return {
        // 对外部公开的数据 & 方法
        click: click,
        focus: focus,

        // 组件渲染函数
        render:function(){
            return h('button', { ref: btn, onClick: handlerClick }, '按钮')
        } 
    }
}

}

// 使用组件



// 调用组件方法
this.$refs.btn.click()

What does the proposed API look like?

before:
setup() {
// return { name:'CY' }
// OR
return function render(){}
}

after:
setup() {
// return { name:'CY' }
// OR
// return function render(){}
// OR
return {
// 模板数据
name:'CY',
// 渲染函数
render:function(){}
}
}

@HcySunYang
Copy link
Member

Please check the RFC about expose vuejs/rfcs#210. Also, you can ask questions on the forum, the Discord server or StackOverflow first.

@github-actions github-actions bot locked and limited conversation to collaborators Oct 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants