Home  >  Q&A  >  body text

Import a component and its properties/methods in another component

If I have the component LogoutButton.vue

export default {
  data() 
  {
      return {

      }
      
  },
  methods: 
  { 
    Logout()
    {
        console.log("something")
    }
  }
}
</script>
<template>
    <button @click="Logout">Logout</button>
</template>

How to use LogoutButton component in other components? I mean how to import this component and its click method in other component?

P粉696605833P粉696605833403 days ago465

reply all(1)I'll reply

  • P粉668113768

    P粉6681137682023-09-13 10:30:32

    <script>
    import LogoutButton from './LogoutButton.vue'
    
    export default {
      components: {
        LogoutButton
      },
      data() 
      {
          return {
    
          }
          
      },
      methods: 
      { 
        // Your different methods
      }
    }
    </script>
    
    <template>
      <div>
        <!-- The template from LogoutButton component will display here -->
        <LogoutButton />
      </div>
    </template>
    

    reply
    0
  • Cancelreply