Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script>
- export default {
- props: ['value'],
- watch: {
- value: function(value) {
- this.relaod(value);
- this.fetchSubCategories(value);
- }
- },
- methods: {
- relaod: function(value) {
- var select = $(this.$el);
- select.val(value || this.value);
- select.material_select('destroy');
- select.material_select();
- },
- fetchSubCategories: function(value) {
- var mdl = this;
- var catID = value || this.value;
- mdl.$emit("reset-subcats");
- if (catID) {
- axios.get(API.URL + '/subcategories/' + catID)
- .then(function(response) {
- response = response.data.subcatData;
- response.unshift({
- subcat_id: '0',
- subcategory_name: 'All Subcategories'
- });
- mdl.$emit("update-subcats", response);
- $('.subdropdown').fadeIn();
- })
- .catch(function(error) {
- if (error.response.data) {
- swal({
- title: "Something went wrong",
- text: "Please try again",
- type: "error",
- html: false
- });
- }
- });
- }
- } else {
- if ($('.subdropdown').is(":visible") == true) {
- $('.subdropdown').fadeOut();
- }
- }
- }
- },
- mounted: function() {
- var vm = this;
- var select = $(this.$el);
- select
- .val(this.value)
- .on('change', function() {
- vm.$emit('input', this.value);
- });
- select.material_select();
- },
- updated: function() {
- this.relaod();
- },
- destroyed: function() {
- $(this.$el).material_select('destroy');
- }
- }
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement