VUE框架前端部分配置axios实现跨域并查询所有电影信息并展示在前端页面上------VUE框架

文章介绍了如何在Vue.js中使用组件(如Movie.vue,Hello.vue,Hello1.vue)进行数据绑定,并通过axios发送HTTP请求从服务器获取数据。还展示了如何使用ElementUI构建表格并根据数据状态设置行样式。
摘要由CSDN通过智能技术生成
<template>
  <!-- <div id="app">
    <img alt="Vue logo" src="./assets/logo.png">
    <HelloWorld msg="Welcome to Your Vue.js App"/> 
  </div> -->
  <div id="app">
     <Movie v-for="movie in movies" :key="movie.id" :title="movie.title" :rating="movie.rating"></Movie>
     <Hello></Hello>
     <Hello1></Hello1>
  </div>
</template>

<script>
// import HelloWorld from './components/HelloWorld.vue'
import Movie from './components/Movie.vue'
import Hello from './components/Hello.vue'
import Hello1 from './components/Hello1.vue'
Movie,name
export default {
  name: 'App',
  data:function(){
    return{
      movies:[]
    }
  },
  created:function(){
    this.$http.get("/Movie/find")
    .then((response)=>{
      this.movies = response.data
    })
  },
  mounted:function(){
  },
  components: {
    // HelloWorld
    Movie,
    Hello,
    Hello1
  }
}
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>

<template>

  <!-- <div id="app">

    <img alt="Vue logo" src="./assets/logo.png">

    <HelloWorld msg="Welcome to Your Vue.js App"/>

  </div> -->

  <div id="app">

     <Movie v-for="movie in movies" :key="movie.id" :title="movie.title" :rating="movie.rating"></Movie>

     <Hello></Hello>

     <Hello1></Hello1>

  </div>

</template>

<script>

// import HelloWorld from './components/HelloWorld.vue'

import Movie from './components/Movie.vue'

import Hello from './components/Hello.vue'

import Hello1 from './components/Hello1.vue'

Movie,name

export default {

  name: 'App',

  data:function(){

    return{

      movies:[]

    }

  },

  created:function(){

    this.$http.get("/Movie/find")

    .then((response)=>{

      this.movies = response.data

    })

  },

  mounted:function(){

  },

  components: {

    // HelloWorld

    Movie,

    Hello,

    Hello1

  }

}

</script>

<style>

#app {

  font-family: Avenir, Helvetica, Arial, sans-serif;

  -webkit-font-smoothing: antialiased;

  -moz-osx-font-smoothing: grayscale;

  text-align: center;

  color: #2c3e50;

  margin-top: 60px;

}

</style>

<template>
  <el-table
    :data="tableData"
    style="width: 100%"
    :row-class-name="tableRowClassName">
    <el-table-column
      prop="id"
      label="ID"
      width="180">
    </el-table-column>
    <el-table-column
      prop="title"
      label="名称"
      width="180">
    </el-table-column>
    <el-table-column
      prop="rating"
      label="评分">
    </el-table-column>
  </el-table>
</template>

<style>
  .el-table .warning-row {
    background: oldlace;
  }

  .el-table .success-row {
    background: #f0f9eb;
  }
</style>

<script>
  export default {
    methods: {
      tableRowClassName({row, rowIndex}) {
        if (rowIndex === 1) {
          return 'warning-row';
        } else if (rowIndex === 3) {
          return 'success-row';
        }
        return '';
      }
    },
    created:function(){
    this.$http.get("/Movie/find")
    .then((response)=>{
      this.tableData = response.data
    })
    },
    data() {
      return {
        tableData: []
      }
    }
  }
</script>

<template>

  <el-table

    :data="tableData"

    style="width: 100%"

    :row-class-name="tableRowClassName">

    <el-table-column

      prop="id"

      label="ID"

      width="180">

    </el-table-column>

    <el-table-column

      prop="title"

      label="名称"

      width="180">

    </el-table-column>

    <el-table-column

      prop="rating"

      label="评分">

    </el-table-column>

  </el-table>

</template>

<style>

  .el-table .warning-row {

    background: oldlace;

  }

  .el-table .success-row {

    background: #f0f9eb;

  }

</style>

<script>

  export default {

    methods: {

      tableRowClassName({row, rowIndex}) {

        if (rowIndex === 1) {

          return 'warning-row';

        } else if (rowIndex === 3) {

          return 'success-row';

        }

        return '';

      }

    },

    created:function(){

    this.$http.get("/Movie/find")

    .then((response)=>{

      this.tableData = response.data

    })

    },

    data() {

      return {

        tableData: []

      }

    }

  }

</script>

import Vue from 'vue';
import App from './App.vue';
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import 'font-awesome/css/font-awesome.min.css';
import axios from 'axios';

axios.defaults.baseURL = "http://localhost:8088"
Vue.prototype.$http = axios
Vue.config.productionTip = false
Vue.use(ElementUI);
new Vue({
  render: h => h(App),
}).$mount('#app')

import Vue from 'vue';

import App from './App.vue';

import ElementUI from 'element-ui';

import 'element-ui/lib/theme-chalk/index.css';

import 'font-awesome/css/font-awesome.min.css';

import axios from 'axios';

axios.defaults.baseURL = "http://localhost:8088"

Vue.prototype.$http = axios

Vue.config.productionTip = false

Vue.use(ElementUI);

new Vue({

  render: h => h(App),

}).$mount('#app')

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值