1.数据库返回数据渲染dom。img图片src的问题
<img :src='"http://www.forsta.cn/webapp/res/upimg/thumb/"+list.img' alt="" width="100%" height="">
属性添加。v-bind缩写 :
不要花括号,需编译为字符。外加单引号
2.同理绑定自定义属性
<div class="pro-list" v-for="list in items" @click="goDetail" :data-value="list.hid"></div>
3.上面2绑定事件获取自身元素的属性值,
e.target 拿到点击的目标元素
event.currentTarget对象就是当前元素,vue传递event获取属性:
goDetail(event){
console.log('go detail');
console.log(event.currentTarget.getAttribute('data-value'))
}
4.vue-router重定向:
{
path:'/',
redirect:'/index'
}
5.build 部署页面空白config - index.js
assetsPublicPath: './',
var path = require('path')
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'],
// 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: {},
// 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
}
}
5.单数据绑定用户名<input type="text" name="username" v-model="uname">
export default {
name: 'hello',
components:{
bot
},
data () {
return {
uname:'',
moveList:[1,2,3,4,5]
}
},
mounted(){
this.init()
},