我正在尝试将数据从vue发布到存在于同一文件夹中的php脚本
在端口8080上执行npm run dev
我的vue应用程序启动时,我的Apache配置使用端口80.我想要做的是将我的vue应用程序中的数据传递到地址http://localhost:8080
我可以使用地址http://localhost:80/project_name
访问的脚本。
我试过这个应用程序作为一个例子github.com/0x90kh4n,当应用程序工作时,我只是克隆它,当我将它添加到我的“真实世界”项目,我使用webpack,babel,npm等我无法访问它,因为应用程序始终向localhost发送请求:8080。尝试像这样更改代理表:
proxyTable: {
'/api' : 'http://localhost:80/project_name'
}
但它不起作用,这是我在我的(单个)vue实例中的代码实现
<script>
import Navigation from './components/partials/Navigation.vue'
export default {
name: 'app',
data () {
return{
name: '',
surname: '',
users: []
}
},
created: function() {
this.fetchData(); // Başlangıçta kayıtları al
},
methods: {
fetchData: function() {
this.$http.get('/api.php')
.then(function(response) {
if (response.body.status == 'ok') {
let users = this.users;
response.body.users.map(function(value, key) {
users.push({name: value.name, surname: value.surname});
});
}
})
.catch(function(error) {
console.log(error);
});
}
},
components: {
Navigation
}
}
在端点中有this file,我不在其中包含代码片段,因为我认为问题是我故事的一部分......
可能值得添加我的/config/index.js
导出:
module.exports = {
build: {
env: require('./prod.env'),
index: path.resolve(__dirname, '../dist/index.html'),
assetsRoot: path.resolve(__dirname, '../dist'),
assetsSubDirectory: 'static',
assetsPublicPath: '/',
productionSourceMap: true,
// Gzip off by default as many popular static hosts such as
// Surge or Netlify already gzip all static assets for you.
// Before setting to `true`, make sure to:
// npm install --save-dev compression-webpack-plugin
productionGzip: false,
productionGzipExtensions: ['js', 'css'],
bundleAnalyzerReport: process.env.npm_config_report
},
dev: {
env: require('./dev.env'),
port: 8080,
autoOpenBrowser: true,
assetsSubDirectory: 'static',
assetsPublicPath: '/',
proxyTable: {
'/api' : 'http://localhost:80/projedt_name'
},
cssSourceMap: false
}