.net项目结构:


程序目录结构:


vue操作:
前提:安装npm ,vue,vue-cli
1、进入控制台窗口
2、进入程序目录
3、运行 vue init webpack webjs 生成webjs及其子目录
4、cd webjs
5、npm install 安装依赖包
6、修改vue配置文件: webjs/config/index.js ,内容:

 // see http://vuejs-templates.github.io/webpack for documentation.
var path = require('path') module.exports = {
build: {
env: require('./prod.env'),
index: path.resolve(__dirname, '../../sccod/views/home/index.cshtml'),
assetsRoot: path.resolve(__dirname, '../../sccod/'),
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'],
// Run the build command with an extra argument to
// View the bundle analyzer report after build finishes:
// `npm run build --report`
// Set to `true` or `false` to always turn it on or off
bundleAnalyzerReport: process.env.npm_config_report
},
dev: {
env: require('./dev.env'),
port: 8080,
autoOpenBrowser: true,
assetsSubDirectory: 'static',
assetsPublicPath: '/',
proxyTable: {
'/api':{
target: 'http://localhost:3472',
changeOrigin:true,
pathRewrite:{
'^/api': '/api'
}
}
},
// CSS Sourcemaps off by default because relative paths are "buggy"
// with this option, according to the CSS-Loader README
// (https://github.com/webpack/css-loader#sourcemaps)
// In our experience, they generally work as expected,
// just be aware of this issue when enabling this option.
cssSourceMap: false
}
}

达到目的:
发布时,运行命令 npm run build ,将在.net mvc 的视图中生成index.cshtml文件,在.net mvc的根建立static目录并将vuejs用到的内容生成在这个地方。
调试时,proxyTable的配置提供了一个映射关系,将http://localhost:8080/api/operator/test的访问指向了http://localhost:3472/api/operator/test。

通过修改app.vue文件内容进行测试:

<template>
<div id="app">
<img src="./assets/logo.png">
<div v-html="svrtest"></div>
<router-view></router-view>
</div>
</template> <script>
require('@/util/util.js');
export default {
name: 'app',
data(){
return{
svrtest:''
};
},
mounted(){
this.$http.post('/api/operator/test').then(response=>{
console.log(response.body);
var obj = response.body;
for(var item in obj){
this.svrtest += '{0}={1}<br>'.format(item,obj[item]);
}
},response=>{
console.log('err',response);
})
}
}
</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>

最新文章

  1. JAVA 1.7 流程控制语句 续
  2. 如何查看经过编码的cookie?
  3. OSG绘制几何图形
  4. 自定义android程序一段时间无操作后的功能
  5. MVC5 学习笔记1
  6. 1、vs2012 mvc3项目ObjectContext类找不到的问题
  7. leetcode - Pascal&amp;#39;s Triangle
  8. hdu_1576A/B(扩展欧几里得求逆元)
  9. rails小重构:将图片加入产品Model
  10. 原生JS封装创建多级菜单函数
  11. Django中提供的6种缓存方式
  12. 阿里云3台机器组成集群配置ssh免密码登陆
  13. Spring之配置文件bean作用域的详细介绍
  14. Android NDK 使用自己的共享库(Import Module)
  15. PAT 1031 Hello World for U
  16. django之http
  17. java字节码文件
  18. qt cout输出中文乱码解决记录
  19. datetime 模块详解 -- 基本的日期和时间类型
  20. ShaderLab内置变量

热门文章

  1. java捕获一个网站页面的全部图片
  2. [Bayes] Concept Search and LDA
  3. C++基础 (杂七杂八的汇总 )
  4. [LeetCode] 96. Unique Binary Search Trees 唯一二叉搜索树
  5. 当代码上传git时,提示Repository not found The requested repository does not exist, or you do not have permission to access it. fatal: Could not read from remote repository. Please make sure you have the corre
  6. Java之第一个Java程序
  7. LeetCode:接雨水【42】
  8. (生鲜项目)01. Vue环境搭建
  9. swoole实现多人游戏的要点
  10. log4j测试示例