Browse Source

started search but api bugged

Bachir Soussi Chiadmi 4 years ago
parent
commit
1a0964d955
2 changed files with 17 additions and 12 deletions
  1. 10 9
      src/components/nav/Search.vue
  2. 7 3
      src/store/modules/search.js

+ 10 - 9
src/components/nav/Search.vue

@@ -1,11 +1,11 @@
 <template>
   <div id="search">
     <form class="" action="index.html" method="post">
-      <label for="keywords">
+      <label for="keys">
         Search
         <input
-          id="keywords"
-          v-model="keywords"
+          id="keys"
+          v-model="keys"
           type="text"
           placeholder="search"
         >
@@ -24,24 +24,25 @@
 
 <script>
 
-import { mapState, mapActions } from 'vuex'
+import { mapActions } from 'vuex'
 
 export default {
   name: 'Search',
   // data: () => ({
-  //   keywords: ''
+  //   typed: ''
   // }),
   computed: {
-    ...mapState({
-      keywords: state => state.Search.keywords
-    })
+    keys: {
+      get () { return this.$store.state.Search.keys },
+      set (value) { this.$store.commit('Search/setKeys', value) }
+    }
   },
   methods: {
     ...mapActions({
       getResults: 'Search/getResults'
     }),
     submit () {
-      console.log('submited', this.keywords)
+      console.log('submited', this.keys)
       this.getResults()
     }
   }

+ 7 - 3
src/store/modules/search.js

@@ -6,7 +6,7 @@ export default {
 
   // initial state
   state: {
-    keywords: '',
+    keys: '',
     results: []
   },
 
@@ -15,6 +15,9 @@ export default {
 
   // mutations
   mutations: {
+    setKeys (state, keys) {
+      state.keys = keys
+    },
     setResults (state, content) {
       state.results = content
     }
@@ -23,12 +26,13 @@ export default {
   // actions
   actions: {
     getResults ({ dispatch, commit, state }) {
+      console.log('getResults', state.keys)
       let params = {
-        search: state.keywords
+        search: state.keys
       }
       // console.log('Search getResults params', params);
       let q = qs.stringify(params)
-      return REST.post(`/search?` + q)
+      return REST.get(`/search?` + q)
         .then(({ data }) => {
           console.log('search REST: data', data)
           // commit('setResults', data.content)