Api.vue 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <template>
  2. <div>
  3. </div>
  4. </template>
  5. <script>
  6. //-----------------------------------------------------------------------------
  7. import vueComponent from '../vueComponent.js';
  8. import wsc from './webSocketConnection';
  9. //import _ from 'lodash';
  10. const componentOptions = {
  11. components: {
  12. },
  13. watch: {
  14. },
  15. };
  16. class Api {
  17. _options = componentOptions;
  18. created() {
  19. this.commit = this.$store.commit;
  20. }
  21. mounted() {
  22. }
  23. async request(params) {
  24. return await wsc.message(await wsc.send(params));
  25. }
  26. async search(query) {
  27. const response = await this.request({action: 'search', query});
  28. if (response.error) {
  29. throw new Error(response.error);
  30. }
  31. return response;
  32. }
  33. async config() {
  34. const response = await this.request({action: 'get-config'});
  35. if (response.error) {
  36. throw new Error(response.error);
  37. }
  38. return response;
  39. }
  40. }
  41. export default vueComponent(Api);
  42. //-----------------------------------------------------------------------------
  43. </script>
  44. <style scoped>
  45. </style>