-
-
Save LiewJunTung/35600eb2380653fe5c73f5321ecfa6eb to your computer and use it in GitHub Desktop.
vue 2 directive with jqueryui
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Vue.directive('datepicker', { | |
bind: function (el, binding, vnode, oldVnode) { | |
$(el).datepicker({ | |
onSelect: function (date) { | |
vnode.context.date = date; | |
} | |
}); | |
}, | |
update: function (el, binding, vnode, oldVnode) { | |
$(el).datepicker('setDate', binding.value); | |
}, | |
unbind: function (el) { | |
$(el).datepicker('destory'); | |
} | |
}); | |
Vue.directive('focus', { | |
// When the bound element is inserted into the DOM... | |
inserted: function (el) { | |
// Focus the element | |
el.blur(); | |
setTimeout(function(){ | |
el.focus(); | |
}, 1000) | |
} | |
}); | |
// create a root instance | |
var vm = new Vue({ | |
el: '#app', | |
data: { | |
date: "10/12/2016" | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Document</title> | |
<script type="text/javascript" src="vue.js"></script> | |
<link rel="stylesheet" href="jquery-ui-1.12.1/jquery-ui.css"> | |
<script src="jquery-1.10.2.js"></script> | |
<script src="jquery-ui-1.12.1/jquery-ui.js"></script> | |
</head> | |
<body> | |
<div id="app"> | |
<input v-focus v-datepicker='date' v-model="date"> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment