소스 검색

Adding help functions to Core

Ecconia 7 년 전
부모
커밋
f3460d34ee
1개의 변경된 파일26개의 추가작업 그리고 9개의 파일을 삭제
  1. 26 9
      src/scripts/core.js

+ 26 - 9
src/scripts/core.js

@@ -5,29 +5,46 @@ export default class {
 		this.vuex = vuex
 	}
 
+	commit(method, data)
+	{
+		this.vuex.commit(method, data)
+	}
+
+	post(path, data)
+	{
+		return axios
+				.post('https://live.ecconia.de' + path, data)
+				.catch((error) => {
+					console.error('Error: ', error)
+				})
+	}
+
+	get(path)
+	{
+		return axios
+				.get('https://live.ecconia.de' + path)
+				.catch((error) => {
+					console.error('Error: ', error)
+				})
+	}
+
 	lol(username, password) {
 		//TODO: return promise somehow
 		//alert('Login attempt as user \'' + username + '\' with password \'' + password + '\'')
 
 		/*
-		axios.get('https://live.ecconia.de/soos')
+		this.get('/soos')
 			.then(function (response) {
 				console.log('Response: ', response.data)
 			})
-			.catch(function (error) {
-				console.error('Error: ', error)
-			})
 		*/
 
-		axios.post('https://live.ecconia.de/login', {
+		this.post('/login', {
 			username: username,
 			password: password,
 		}).then((response) => {
 			console.log('Response: ', response.data)
-			this.vuex.commit('setUser', response.data)
-		})
-		.catch((error) => {
-			console.error('Error: ', error)
+			this.commit('setUser', response.data)
 		})
 	}
 }