前言: 以前使用的input输入框,placeholder的值是固定不变的,现在根据需求,placeholder的值不再是唯一的,就需要动态绑定placeholder。

效果图:

代码实现:

       <div class="box flex">
          <span v-if="indexNav == 0">登录密码</span>
          <span v-else>交易密码</span>
          <input
            type="password"
            :placeholder="psdPlaceholder"
            v-model.trim="psd"
          />
        </div>

 然后用computed属性

  computed: {
  //psdPlaceholder 是你需要用到的名字
    psdPlaceholder() {
      return this.indexNav == 0
        ? "请输入您的新登录密码"
        : "请输入您的新交易密码";
    },
  },

 转发自:vue 动态绑定placeholder_pxhing的博客-CSDN博客_placeholder动态绑定

Logo

基于 Vue 的企业级 UI 组件库和中后台系统解决方案,为数万开发者服务。

更多推荐