【问题标题】:Is there any way to set selected option in Vue DatePicker?有没有办法在 Vue DatePicker 中设置选定的选项?
【发布时间】:2021-11-11 10:46:30
【问题描述】:

我正在使用 Vue Material - 在我的 vue js 项目中选择组件。我想动态设置组件的选定值。我浏览了文档https://www.creative-tim.com/vuematerial/components/select,但找不到我正在寻找的解决方案。有什么方法可以完成这个任务。

提前谢谢你

【问题讨论】:

  • data 中为 v-model 设置值,如文档中的示例所示:movie: 'godfather'

标签: vue.js vue-component vue-material md-select


【解决方案1】:
<template>
  <md-field class="box">
    <label for="movie">Movie</label>
    <md-select v-model="movie" name="movie" id="movie">
      <md-option v-for="opt in options" :key="opt.value" :value="opt.value">
        {{ opt.name }}
      </md-option>
    </md-select>
  </md-field>
</template>

<script>
export default {
  name: "BasicSelect",
  data: () => ({
    movie: "",
    options: [
      { value: "fight-club", name: "Fight Club" },
      { value: "godfather", name: "Godfather" },
      { value: "scarface", name: "Scarface" },
    ],
  }),
  mounted() {
    // Here we set default selected value, you can change it any time
    this.movie = this.options[0].value;
  },
};
</script>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-20
    • 2022-01-05
    • 2018-07-02
    • 1970-01-01
    • 2012-05-15
    • 2010-11-11
    相关资源
    最近更新 更多