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

methods functions can be used in custom elements #8318

Closed
GuoJikun opened this issue May 15, 2023 · 1 comment
Closed

methods functions can be used in custom elements #8318

GuoJikun opened this issue May 15, 2023 · 1 comment
Labels
✨ feature request New feature or request

Comments

@GuoJikun
Copy link

What problem does this feature solve?

Functions in methods cannot be called directly from a custom element(在自定义元素中无法直接调用methods中的方法)

What does the proposed API look like?

methods functions can be used in custom elements(methods的函数可以在自定义元素上使用)

example(示例)

// setup
// Button.ce.vue 

<script setup>
import { defineExpose } from 'vue'
const test = ()=>{
  console.log('123')
}
defineExpose({
  test
})
</script>

<template>
  <div class="btn">
    <slot></slot>
  </div>
</template>
// option
// Button.ce.vue   

<script>
import { defineComponent } from 'vue'

defineComponent({
  methods: {
    test(){
      console.log('123')
    }
  }
})
</script>

<template>
  <div class="btn">
    <slot></slot>
  </div>
</template>
// app.vue
<script setup>
import { defineCustomElement, onMounted } from 'vue'
import Button from './Button.ce.vue'
const IButton = defineCustomElement(Button)
customElements.define('i-button', IButton)

onMounted(()=>{
  document.querySelector('#test').test() // like this(这种方式调用)
})
</script>
<template>
  <div>
    <i-button id="test">test</i-button>
  </div>
</template>
@GuoJikun GuoJikun added the ✨ feature request New feature or request label May 15, 2023
@LinusBorg
Copy link
Member

duplicate: #5540

@github-actions github-actions bot locked and limited conversation to collaborators Sep 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
✨ feature request New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants