物件加上自訂的屬性資料
但在較舊的瀏覽器上若對已經存在的屬性去做重新設定則會發生錯誤
例 要在fn物件加上一個name的屬性
Object.defineProperty(fn, "name", { value: 'testName'})
這在android 4.x版預設的瀏覽器上會發生錯誤如果改用其他property name 則可正常運作
例
Object.defineProperty(fn, "fnName", { value: 'testName'})
Object.defineProperty(fn, "name", { value: 'testName'})
這在android 4.x版預設的瀏覽器上會發生錯誤Object.defineProperty(fn, "fnName", { value: 'testName'})
{
"name": "simplesocket",
"version": "1.0.0",
"description": "build simple socket server excute file for web",
"main": "lib/index.js",
"bin": "lib/index.js",
"scripts": {
"start": "babel -s inline -d lib -w src | nodemon lib/index.js",
"build": "pkg package.json --target node8-macos-x64,node8-win-x86 --out-dir output",
"prepublish": "node_modules/babel-cli/bin/babel.js src --out-dir lib"
},
"babel": {
"presets": [
"es2015"
]
},
"pkg": {
"scripts":"node_modules/extra../**/*.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/ozzysun/simpleSocket.git"
},
"keywords": [
"socketio",
"express",
"pkg"
],
"author": "ozzysun",
"license": "ISC",
"bugs": {
"url": "https://github.com/ozzysun/simpleSocket/issues"
},
"homepage": "https://github.com/ozzysun/simpleSocket#readme",
"dependencies": {
...
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-core": "^6.26.0",
"babel-preset-es2015": "^6.24.1",
"nodemon": "^1.11.0"
}
}
import Vuelidate from 'vuelidate'
Vue.use(Vuelidate)
import { validationMixin } from 'vuelidate'
mixins:[validationMixin],
此時就可以在元件內加入validations來設定相關要驗證的規則
validations可以是物件
validations:{
}
也可以是method
validations(){
return {}
}
import { required, minLength,maxLength,numeric } from 'vuelidate/lib/validators'
<template>
<div>
<input type="password" v-model.trim="pwd">
<button v-if="isActiveForSend" @click="clickSendBtn">送出</button>
<span>這欄位所有狀態{{$v.pwd}}</span>
</div>
</template>
<script>
import { validationMixin } from 'vuelidate'
import { required, minLength,maxLength,numeric } from 'vuelidate/lib/validators'
export default {
mixins:[validationMixin],
validations(){
return {
pwd:{
required,
numeric,
minLength: minLength(6),
maxLength:maxLength(6)
}
}
},
computed:{
isActiveForSend(){
return this.$v.pwd.required&&this.$v.pwd.numeric&&this.$v.pwd.minLength&&this.$v.pwd.maxLength
}
},
}
</script>
@import url("./style01.css") screen and (min-width: 640px)