웹개발 지식

백 / 프론트(vue) 연결

추띠기 2023. 2. 3. 16:22

뷰 설치 및 필요 npm 설치

npm init
npm i
npm i -g npm@latest
npm i -g @vue/cli

npm i axios
npm run serve

 

vue.config.js에 연결 작업

프론트 : 8080 / 백 : 9000

devServer: {
    proxy: {
      "/api": {
         target: 'http://localhost:9000/',
         pathRewrite: {'^/': ''},
         changeOrigin: true

      }
    },
    port : 8080
  },

axios 사용법

<script>

export default {
    methods: {
      함수명(){
        axios.post('매핑주소',{
        	// 보낼 데이터
        }).then((res) => {
        	// 응답
          console.log(res)          
        }).catch((err)=>{
          console.log(err)
        })
      }
    }
  }
  
</script>