vue开发总结

 

1.监听回车事件

不封装的组件用  @keyup.enter  
封装的组件如el-input用  @keyup.enter.native
例:searchComplete: function (e) {
  var keyCode = window.event? e.keyCode:e.which;
  // console.log('回车搜索',keyCode,e);
  if(keyCode === 13){
    this.isShowSearchIcon = false;
    this.$refs.water.searchPoster(this.posterName);
  }
}

 

2.防止冒泡事件

@click.stop="editText()"

 

3.父子组件传值

父组件代码中 <water_falls  @getWaterfallsPosterNum="getPosterNum" ref="water"></water_falls>
父组件事件中  this.$refs.water.searchPoster(this.posterName);
searchPoster为子组件事件,this.posterName 子组件获取父组件的值
子组件中:
searchPoster: function (posterName) {
  this.posterName = posterName;
  console.log("this.posterName:" + this.posterName);
}
子组件调用父组件事件:

子组件事件中: this.$emit('getWaterfallsPosterNum', _this.sumPosterNum);
父组件事件获取子组件的值
父组件中:
getPosterNum: function (data) {
  console.log("data:::::" + data);
  this.totleList = data;
},

4.全局使用插件

例:lodash

main.js中:
import _ from 'lodash'
Vue.prototype._ = _;
使用:this._.cloneDeep

5.vue遮罩:

<div v-show="showInfo" class="clothesInfo" @touchmove.prevent="">
  <!--遮罩层-->
  <div class="top_info">

  </div>
  <!--校服信息-->
  <div class="all_info">
  </div> 
</div>

css:

.clothesInfo {
  position: fixed;
  bottom: 0;
  width: 100%;
  height: 100%;
  z-index: 1000;
  .top_info {
    width: 100%;
    height: 10%;
    opacity: 0.3;
    filter: alpha(opacity=30);
    background-color: #000;
  }
  .all_info {
    width: 100%;
    height: 90%;
    background-color: white;
   }
 }

6.vue访问url去除#

router/index.js页面中代码

//mode 可选的参数有 hash 和  history;
//hash: 默认为hash, 如果使用hash的话,页面的地址就会加上 # 号就会比较不好看,如我们的地址变成如下:http://localhost:8080/#/
//history: 我们使用history的话,那么访问页面的时候就和平常一样,不带井号的;如下地址也可以访问 http://localhost:8080/
let router = new Router({
  base: contextPath || '/',// 配置单页应用的基路径
  mode: 'history',// 访问路径不带井号
  routes: routerConfig.routeConfig
});

7.vue路由跳转

1.router-link标签跳转

<router-link :to="{path:'/view/posterDetail',query:{id:item.id}}">
</router-link>

2.$router.push  传参方式query和params  query要用path来引入,params要用name来引入,接收参数都是类似的,分别是this.$route.query.name和this.$route.params.name。 
query更加类似于我们ajax中get传参,params则类似于post,说的再简单一点,
前者在浏览器地址栏中显示参数,后者则不显示

this.$router.push({path: '/view/article', query: {bookcaseId: bookcase._id}});

3.this.$router.replace(location) 不能回退 替换掉当前history

4.路由回退:
 this.$router.go(-1);

8. $set 给data对象新增属性,并触发视图更新

例:给poster新增src属性并赋值触发视图更新 this.$set(poster, 'src', url);

9.vue build构建路径问题

(1)history模式:config下的index.js :

        assetsPublicPath: '/'

        hash模式: config下的index.js :

        assetsPublicPath: './'

(2)build下的utils.js添加代码:

if (options.extract) {
  return ExtractTextPlugin.extract({
    use: loaders,
    fallback: 'vue-style-loader',
    publicPath: '../../'  // 添加的代码
  })
} else {
  return ['vue-style-loader'].concat(loaders)
}

(3)build下的webpack.prod.conf.js添加代码:

 output: {
  publicPath: './',
  path: config.build.assetsRoot,
  filename: utils.assetsPath('js/[name].[chunkhash].js'),
  chunkFilename: utils.assetsPath('js/[id].[chunkhash].js')
 },

10.手机端预览vue项目

修改config下的index.js :

host: '0.0.0.0', // 手机预览调试 host需改为0.0.0.0

 

11.vue手机端输入法把底部(底部 fixed定位)顶上去问题

isShowFooter:true,
docHeight: document.documentElement.clientHeight,  //一开始的屏幕高度
showHeight: document.documentElement.clientHeight,   //一开始的屏幕高度
watch:{
  showHeight: 'inputType'
},
methods: {
// 检测屏幕高度变化
inputType() {
  if (!this.timer) {
    this.timer = true;
    let that = this;
    setTimeout(() => {
      if (that.docHeight > that.showHeight) {
        //显示class
        this.isShowFooter = false;
      } else if (that.docHeight <= that.showHeight) {
        //显示隐藏
        this.isShowFooter = true;
      }
      that.timer = false;
    }, 20)
  }
},
}

也可以改成相对定位

 

12.手机端预览vue项目看日志

index.html中

<script src="https://cdnjs.cloudflare.com/ajax/libs/vConsole/3.3.0/vconsole.min.js"></script>
<script>
  var vConsole = new VConsole(); // 手机端日志查看vConsole实例化
</script>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vue开发Chrome插件需要以下几个步骤: 1. 创建一个Vue项目:首先需要安装Vue CLI来创建一个新的Vue项目。在命令行中运行如下命令来创建项目: ``` vue create chrome-extension-project ``` 根据提示选择需要的配置项,如Babel和Router。创建完成后,进入项目目录: ``` cd chrome-extension-project ``` 2. 配置Chrome插件:在项目根目录下创建一个`manifest.json`文件,该文件用于配置插件的基本信息,例如插件名称、描述、图标、权限等。详细的配置可以参考Chrome官方文档。 3. 开发Vue组件:使用Vue开发插件的界面。可以在`src`目录下创建Vue组件,并在需要的地方使用它们。可以使用Vue Router来管理插件的不同页面或者使用Vuex来处理全局状态。 4. 构建插件:在命令行中运行如下命令来构建插件: ``` npm run build ``` 该命令会将Vue项目打包成一组静态文件,可以在`dist`目录中找到构建好的插件文件。 5. 导入插件:在Chrome浏览器中打开扩展程序页面(在地址栏输入`chrome://extensions`),点击右上角的“开发者模式”,然后点击“加载已解压的扩展程序”,选择之前构建好的插件文件夹(即`dist`目录)。 6. 调试和发布:在Chrome浏览器中调试已加载的插件,可以通过“检查视图”来调试Vue组件。如果插件开发完成并通过测试,可以在Chrome Web Store上发布插件,供用户下载和使用。 总结起来,Vue开发Chrome插件的过程可以概括为:创建Vue项目,配置插件信息,开发Vue组件,构建插件文件,导入插件到Chrome浏览器,调试并最终发布。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值