naive-ui/demo/documentation/components/dropdown/enUS/trigger.md
2019-12-03 21:48:34 +08:00

1.3 KiB
Raw Blame History

Trigger

<n-dropdown @select="handleSelect" trigger="hover">
  <template v-slot:activator>
    <n-button>Hover! On the Green Light!</n-button>
  </template>
  <n-dropdown-item
    v-for="hotel in hotels"
    :key="hotel"
    :name="hotel.toLowerCase()"
    :label="hotel"
  />
</n-dropdown>

<n-dropdown @select="handleSelect" trigger="click" :focusable="false">
  <template v-slot:activator>
    <n-button>Click! On the Green Light</n-button>
  </template>
  <n-dropdown-item
    v-for="hotel in hotels"
    :key="hotel"
    :name="hotel.toLowerCase()"
    :label="hotel"
  />
</n-dropdown>

<n-dropdown @select="handleSelect" trigger="manual" v-model="showDropdown">
  <template v-slot:activator>
    <n-button @click="handleClick">Oh! Manually By Myself!</n-button>
  </template>
  <n-dropdown-item
    v-for="hotel in hotels"
    :key="hotel"
    :name="hotel.toLowerCase()"
    :label="hotel"
  />
</n-dropdown>
export default {
  data () {
    return {
      hotels: [
        'Marina Bay Sands, Singapore', 'Browns Hotel, London', 'Atlantis Bahamas, Nassau', 'The Beverly Hills Hotel, Los Angeles'
      ],
      showDropdown: false
    }
  },
  methods: {
    handleSelect (name) {
      this.$NMessage.info(name)
    },
    handleClick () {
      this.showDropdown = !this.showDropdown
    }
  }
}
.n-button {
  margin: 0 8px 12px 0;
}