当前位置: 首页 > news >正文

中国最大的摄影网站网站建设是基于

中国最大的摄影网站,网站建设是基于,福建seo优化,个人网站开发需求分析以下是必须为迁移到 vue3 进行调整的要点,以便 vue2 项目可以在 vue3 上正常运行。 1. 在index.js中创建应用程序实例 // Before - Vue 2 import Vue from vue import App from ./App // with no need for vue3 Vue.config.productionTip false // vue3 is no lon…

以下是必须为迁移到 vue3 进行调整的要点,以便 vue2 项目可以在 vue3 上正常运行。


1. 在index.js中创建应用程序实例

// Before - Vue 2
import Vue from 'vue'
import App from './App'
// with no need for vue3
Vue.config.productionTip = false
// vue3 is no longer needed
App.mpType = 'app'
const app = new Vue({
...App
})
app.$mount()// After - Vue 3
import App from './App'
import { createSSRApp } from 'vue'
export function createApp() {const app = createSSRApp(App)return {app}
}

2. 添加全局属性,例如:全局网络请求

// Before - Vue 2
Vue.prototype.$http = () => {};// After - Vue 3
const app = createApp({});
app.config.globalProperties.$http = () => {};

3. 插件使用,例如:使用vuex的存储

// Before - Vue 2
import store from "./store";
Vue.prototype.$store = store;// After - Vue 3
import store from "./store";
const app = createApp(App);
app.use(store);

4. 项目根目录必须创建一个index.html文件

复制并粘贴以下内容:

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8" /><meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" /><title></title><!--preload-links--><!--app-context--></head><body><div id="app"><!--app-html--></div><script type="module" src="/main.js"></script></body>
</html>

只支持使用ES6模块规范,需要将commonJS更改为ES6模块规格

5. 模块导入,例如:

//Before - Vue 2, use commonJS
var utils = require("../../../common/util.js");//After - Vue 3, only ES6 module is supported
import utils from "../../../common/util.js";

6. 模块导出,例如:

//Before - Vue 2, if dependent, export using commonJS
module.exports.X = X;//After - Vue 3, can be manually changed to ES6 for export
export default { X };

7. vuex 使用情况

// Before - Vue 2import Vue from 'vue'import Vuex from 'vuex'Vue.use(Vuex)const store = new Vuex.Store({state: {}})export default store// After - Vue 3import { createStore } from 'vuex'const store = createStore({state: {}})export default store
  • 避免在同一元素上同时使用v-if和v-for

    然而,在Vue3中,v-if总是在v-for之前成为有效的。以上内容与 Vue3的预期不符。由于语法上的模糊性,建议避免在同一元素上同时使用两个。

  • 适应生存周期

    在Vue3中,组件卸载的生存周期被重命名为

    • destroyed已修改为 unmounted
    • beforeDestroy已修改为 beforeUnmount
  • 对事件的调整

    Vue3 现在提供了一个 emits选项,类似于现有的 props选项。这个选项可以用来定义一个组件可以向其父对象发出的事件。

8. 强烈建议使用 emits以记录每个组件发出的所有事件。

这一点尤为重要,因为 .native修饰符已被删除。 emits现在,所有未使用的已声明事件的监听器都将被包含在组件中。 $attrs.默认情况下,侦听器将绑定到组件的根结点。

<template><button @click="onClick">OK</button>
</template>
<script>
export default {emits: ['click'],methods:{onClick(){this.$emit('click', 'OK')}}
}
</script>

与 Vue2相比, Vue3 对v-model的适应性有了很大变化。您可以使用多种v-model。 model,相应的语法也发生了变化。

...当为自定义组件修改modelValue时, Vue3 v-model props和事件的默认名称将被更改。 props.value已更改为 props.modelValue和 event.value已更改为 update:modelValue

export default {props: {// value:String,//Replace value as modelValuemodelValue:String}
}

事件返回:更改之前的 this.$emit('input')到 this.$emit('update:modelValue'),此步骤将在vue3中省略。

9. 自定义组件上的v-model等同于传递modelValue prop并接收抛出的update:modelValue事件:

  <ChildComponent v-model="pageTitle" /><!-- Abbreviation for the following: --><ChildComponent:modelValue="pageTitle"@update:modelValue="pageTitle = $event"/>

10. 如果需要更改模型名称,作为组件中模型选项的替代方案,我们现在可以向v-model传递一个参数:

  <ChildComponent v-model:title="pageTitle" /><!-- Abbreviation for the following: --><ChildComponent :title="pageTitle" @update:title="pageTitle = $event" />

11. 对时段的改编

Vue3 将不支持使用 slot="xxx",请使用 v-slot:xxx使用。

<!-- Usage supported by Vue2 -->
<uni-nav-bar><view slot="left" class="city"><!-- ... --></view>
</uni-nav-bar>
<!-- Usage supported by Vue3 -->
<uni-nav-bar><template v-slot:left><view class="city"><!-- ... --></view></template>
</uni-nav-bar>

从 Vue 3.0+ 开始,过滤器已被删除且不再受支持,建议用方法调用或计算属性替换它们。

如果您想了解更多,请浏览vue官网。文章来源于uniapp官网,文章地址:从vue2迁移到vue3。

如果文章对您有帮助,还请您点赞支持
感谢您的阅读,欢迎您在评论区留言指正分享

http://www.dtcms.com/a/559681.html

相关文章:

  • 设计网站大全备案变更网站信息
  • 虚拟网站建设步骤网络平台运营是做什么的
  • 织梦移动端网站怎么做如何建立自己的网站教程
  • 怎么查看网站根目录中国互联网协会新春茶话会
  • 自己的博客和自己的网站做友链无人在线观看高清视频单曲直播
  • 广州市公司网站建设南宁网站建设是什么
  • 网站的后台管理员系统建设教程求一个自己做的网站链接
  • 怎么看网站有没有做百度推广wordpress免费资源网
  • 负面信息搜索引擎 网站高端品牌包包
  • wordpress添加自定义tag标签企业网站优化
  • 阿里服务器怎么做网站服务器平台网站开发公司
  • 印后设备网站建设高粱seo博客
  • 企业网站建设知识应用技能舟山网站建设
  • 广西城市建设学校手机官方网站微网站趋势
  • 做木皮的网站asp.net网站开发四酷全书
  • 大学生做静态网站网站不稳定有什么影响
  • h5页面制作工具 软件专业的网站优化公司排名
  • 企业网站找谁做好在中山网
  • dfs|位|dirs
  • 网站后端开发网页设计与制作试卷分析报告
  • 什么是网站交互wordpress 装修 模板
  • 互联网软件开发是什么wordpress导航如何优化
  • 仙游哪里可以做网站的虚拟主机 删除网站缓存
  • 石家庄网站定制制作外国ps素材网站
  • 怎么申请 免费网站空间wordpress支付文件在哪
  • 西宁最好网站建设公司程序开发总结
  • 网站建设課程广东网站建设微信网站定制
  • 龙华做棋牌网站建设企业排名优化公司
  • 廊坊手机模板建站免费做二维码网站
  • 网站建设全教程广州做企业网站找哪家公司好