vue输入密码组件_Vue.js密码输入组件,其中包括一个用于显示密码的切换开关

vue输入密码组件

Vue密码3.x (vue-password 3.x)

A Vue.js password input component that includes a toggle to show the password and a customizable strength meter.

Vue.js密码输入组件,包括一个用于显示密码的开关和一个可自定义的强度计。

Please note, VuePassword 3.x removes support for the zxcvbn library. The library appears to no longer be maintained. If you would still like to use it, you can still pull in the library and pass the VuePassword value to it to calculate the strength. Examples coming soon.

请注意,VuePassword 3.x删除了对zxcvbn库的支持。 该库似乎不再维护。 如果仍要使用它,您仍然可以拉入库并将VuePassword值传递给它以计算强度。 示例即将到来。

安装 (Install)

Install the package using npm.

使用npm安装软件包。

npm install --save vue-password

The VuePassword component adds support for a toggle to hide and show the password as well as a meter to show the current strength of the password. This component does not automatically calculate the strength, however, a library like zxcvbn can be used to pass the strength values as props.

VuePassword组件增加了对用于隐藏和显示密码的切换开关以及显示密码当前强度的仪表的支持。 该组件不会自动计算强度,但是,可以使用像zxcvbn这样的库将强度值作为prop传递。

import VuePassword from 'vue-password';

export default {
    ...
    components: {
        VuePassword,
    },
    ...
};

用法 (Usage)

Use the props in your HTML and apply a v-model attribute for the password and any additional props for the desired configuration. The password input uses the $attrs attributes, so form validation props such as required, minlength, and maxlength will function on the input element. The following example shows how vue-password could be used in a registration form using Tailwind CSS.

在HTML中使用道具,并为密码设置v-model属性,并为所需配置应用其他道具。 密码输入使用$ attrs属性,因此表单验证道具(例如required,minlength和maxlength)将在输入元素上起作用。 以下示例显示了如何使用Tailwind CSS在注册表单中使用vue-password。

Java脚本 (Javascript)
import Vue from 'vue'
import VuePassword from 'vue-password'

new Vue({
  el: '#app',
  components: {
    VuePassword
  },
  data {
    user: {
      email: '',
      password: ''
    }
  }
})
HTML (HTML)
<form>
    <div class="mb-4">
        <label for="password">Password</label>
        <VuePassword
            v-model="password1"
            id="password1"
            :strength="strength"
            type="text"
        />
    </div>
</form>

道具 (Props)

Use the following props to configure the password input.

使用以下道具来配置密码输入。

PropDefaultDescription
classes'form-control'Set the classes for the input element. The default is the 'form-control' class used by Twitter Bootstrap. A string or array of classes can be passed in the prop.
disableStrengthfalseDisable the password strength meter and messages.
disableTogglefalseDisable the password input toggle to show/hide the password.
strengthClasses['VuePassword--very-weak', 'VuePassword--weak', 'VuePassword--medium', 'VuePassword--good', 'VuePassword--great']Set the classes used to style the strength message and strength meter. This should be an array of five classes. The classes are applied depending on the current strength score of the password (0-4).
strengthMessages['Very Weak Password', 'Weak Password', 'Medium Password', 'Strong Password' 'Very Strong Password']Set the messages that appear depending on the strength score of the password. This should be an array of five messages.
Struts 默认 描述
“形式控制” 设置输入元素的类。 默认值为Twitter Bootstrap使用的“ form-control”类。 字符串或类数组可以在prop中传递。
disableStrength 禁用密码强度计和消息。
disableToggle 禁用密码输入切换按钮以显示/隐藏密码。
strengthClasses [“ VuePassword –非常弱”,“ VuePassword –弱”,“ VuePassword –中”,“ VuePassword –好”,“ VuePassword –很好”] 设置用于设置强度消息和强度计样式的类。 这应该是五个类的数组。 根据密码的当前强度得分(0-4)应用类别。
strengthMessages [“非常弱密码”,“弱密码”,“中等密码”,“强密码”,“非常强密码”] 根据密码强度得分设置显示的消息。 这应该是五个消息的数组。

大事记 (Events)

The password input emits an input event to use with v-model. Other events are binded use v-on="listeners".

密码输入发出一个输入事件以与v模型一起使用。 其他事件使用v-on =“ listeners”绑定。

插槽 (Slots)

Named slots can be used to change the layout of the password toggle, strength meter, and strength messages.

命名的插槽可用于更改密码切换器,强度计和强度消息的布局。

SlotScopeDescription
password-input
  • strength: Strength value

  • type: Current element type ('password or text')

  • updatePassword: Method to update the password value.

  • value: Current password value

Use this to replace the input element. The content provided by the slot must include an input field, preferably of type password.
password-toggletoggle: Method to change the input type attribute from 'password' to 'type'Use this named slot to change the layout of the password toggle.
password-hideUse this named slot to change the password hide icon.
password-showUse this named slot to change the password show icon.
strength-meter
  • strength: Strength value

  • strength-class: Current strength class

  • strength-classes: The array of strength classes

  • strength-message: Current strength message

  • strength-messages: The array of strength messages

Use this named slot to change the layout of the password strength meter.
插槽 范围 描述
密码输入
  • 强度:强度值

  • 类型:当前元素类型(“密码或文本”)

  • updatePassword:更新密码值的方法。

  • 值:当前密码值

使用它来替换输入元素。 插槽提供的内容必须包含一个输入字段,最好是password类型。
密码切换 toggle:将输入类型属性从“密码”更改为“类型”的方法 使用此命名插槽更改密码切换器的布局。
隐藏密码 使用此命名插槽更改密码隐藏图标。
密码显示 使用此命名插槽更改密码显示图标。
强度计
  • 强度:强度值

  • 强度等级:当前强度等级

  • 强度等级:强度等级的数组

  • strength-message:当前强度信息

  • 强度消息:强度消息的数组

使用此命名插槽更改密码强度计的布局。

示例:使用自定义输入 (Example: Use custom input)

<VuePassword
    v-model="user.password"
>
    <div
        v-slot:password-input="props"
        class="control has-icons-left"
    >
        <input
            class="input"
            type="password"
            placeholder="Text input"
            :value="props.value"
            @input="props.updatePassword"
        />
    </div>
</VuePassword>

自定义强度示例 (Custom Strength Example)

HTML (HTML)
<form>
    <label for="password">Password</label>
    <VuePassword
        v-model="user.password"
        :strength="score"
        @input="updateStrength"
    />
</form>
Java脚本 (Javascript)
import VuePassword from 'vue-password'

new Vue({
    el: '#app',
    components: {
        VuePassword,
    },
    data: {
        score: 0,
        user: {
            password: ''
        }
    },
    methods: {
        updateStrength(password) {
            /**
             * The input event sends the current password and
             * any included user inputs (email in this case).
             *
             * Calculate the score here either using a custom
             * javascript library or a request to the server.
             *
             * The strength must be an integer between 0 and 4.
             */
        }
    }
});

翻译自: https://vuejsexamples.com/a-vue-js-password-input-component-that-includes-a-toggle-to-show-the-password/

vue输入密码组件

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vue开关百度地图的热力图显示,可以通过设置一个开关变量,并在该变量值改变时切换地图的样式,从而实现。具体实现步骤如下: 1. 在 Vue 组件中声明一个开关变量,用于控制热力图的显示状态。 ```javascript <template> <div> <input type="checkbox" v-model="isHeatmapVisible" @change="toggleHeatmap" /> <div id="map"></div> </div> </template> <script> export default { data() { return { isHeatmapVisible: false, // 热力图显示状态开关 map: null // 地图对象 } }, mounted() { // 初始化地图对象 this.map = new BMap.Map('map') }, methods: { toggleHeatmap() { // 切换热力图的显示状态 const styleJson = this.isHeatmapVisible ? [ { featureType: 'heatmap', elementType: 'all', stylers: { visibility: 'on' } } ] : [ { featureType: 'heatmap', elementType: 'all', stylers: { visibility: 'off' } } ] this.map.setMapStyle({ styleJson }) } } } </script> <style> #map { width: 100%; height: 400px; } </style> ``` 2. 在组件的 `mounted()` 钩子函数中,初始化地图对象,并将其赋值给组件的 `map` 属性。 3. 在组件的 `toggleHeatmap()` 方法中,根据开关变量 `isHeatmapVisible` 的值,设置地图样式中的热力图显示状态,并调用地图对象的 `setMapStyle()` 方法切换地图样式。 4. 在组件的模板中,使用一个复选框来绑定开关变量 `isHeatmapVisible`,并在复选框的 `change` 事件中调用 `toggleHeatmap()` 方法切换热力图的显示状态。 上述代码中,设置地图样式时,可以通过设置 `styleJson` 数组中的 `stylers` 属性来设置地图样式的具体内容。在该例中,将 `visibility` 设置为 `'on'` 或 `'off'` 即可控制热力图的显示状态。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值