# vue-jd-h5 **Repository Path**: wiliam216/vue-jd-h5 ## Basic Information - **Project Name**: vue-jd-h5 - **Description**: 基于vue2.6+ ,vue3.0.0-beta.1,vue3, vue-cli3,mockjs,仿京东淘宝的,移动端H5电商平台! - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: vue-next - **Homepage**: http://gankai.gitee.io/vue-jd-h5/#/index - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 9 - **Created**: 2024-07-23 - **Last Updated**: 2024-07-23 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README
https://user-images.githubusercontent.com/37830362/173991179-71272ccb-bf69-441f-8f15-46e8da403d2a.mov # vue3-jd-h5

Twitter GitHub issues GitHub forks GitHub stars

English| 简体中文

## Project Introduction `vue3-jd-h5` is an e-commerce H5 page front-end project, based on **Vue 3.0.0** + **Vant 3.0.0** implementation, mainly including homepage, category page, my page, shopping cart, etc. . 📖Local offline code **vue2.6** in the branch demo , use **mockjs** data for development, please click for the renderings 🔗 Here ⚠️The master branch is the code of the online production environment, because part of the background interface has been hung up 😫, the actual effect may not be seen. 📌 There are still many shortcomings in this project. If you have partners who want to contribute to this, please send us a PR or issue; 🔑 This project is free and open source. If you have a partner who wants to carry out secondary development on a secondary basis, you can clone or fork the entire warehouse. If it can help you, I will be very happy. If you think this project is good, please give it back Start! 🙏 ## Vue3 build steps 1. First, select a file locally and clone the code locally: ```bash git clone https://github.com/GitHubGanKai/vue-jd-h5.git ``` 2. View all branches: ```bash gankaideMacBook-Pro:vue-jd-h5 gankai$ git branch -a demo vue-next dev feature gh-pages * master remotes/origin/HEAD -> origin/master remotes/origin/demo remotes/origin/vue-next remotes/origin/dev remotes/origin/feature remotes/origin/gh-pages remotes/origin/master ``` 3. Switch to the branch **vue-next** to start development! 4. Run the command in the IDEA command line: npm install, download related dependencies; 5. 🔧 Development environment Run the command in the IDEA command line: `npm run dev`, run the project; 6. 📦Run the command in the IDEA command line: `npm run dll:build`, package the project, 📱scan the QR code below 👇 to view!
## Initialization of the project 💡If you are slow when installing the package, it is because the NPM server is abroad. Here is a tool for you to switch NPM mirroring at any time. 👉[NRM](https://www.npmjs.com/package/nrm ), sometimes when we are developing, in order to speed up the installation of the installation package, we need to switch the mirror source to domestic, but if we need to publish some of our own components to NPM, we have to switch back and forth again. With this We are much more convenient! Use `$ npm install -g nrm` to install globally, and then use `nrm ls` to view all mirrors: ```bash gankaideMacBook-Pro:~ gankai$ nrm ls npm -------- https://registry.npmjs.org/ * yarn ------- https://registry.yarnpkg.com/ cnpm ------- http://r.cnpmjs.org/ taobao ----- https://registry.npm.taobao.org/ nj --------- https://registry.nodejitsu.com/ npmMirror -- https://skimdb.npmjs.com/registry/ edunpm ----- http://registry.enpmjs.org/ ``` If you need to use Taobao mirror, execute: `nrm use taobao` You can switch the source at any time, of course, there is also an npm package version management tool [nvm](https://github.com/nvm-sh/nvm), mainly for management In the package version, if you are interested, you can find out for yourself, here is not a long time 😊! ### Installation Enter the root directory of the project that was cloned just now, install related dependencies, and experience the new features of vue3. `npm` installation: ```javascript npm install ``` `yarn` installation: ```javascript yarn ``` **CDN** ```html ``` ### use In the entry file `main.js`: ```javascript import Vue from 'vue'; import VueCompositionApi from '@vue/composition-api'; Vue.use(VueCompositionApi); ``` After installing the plug-in, you can use the new [Composition API](https://vue-composition-api-rfc.netlify.com/) to develop components. ⚠️At present, vue officially provides a plug-in for vue-cli [vue-cli-plugin-vue-next](https://github.com/vuejs/vue-cli-plugin-vue-next), you can also directly Add the latest version directly to the project! ```bash # in an existing Vue CLI project vue add vue-next ```
If you have a small partner who wants to experience the new version from scratch, you can use this method to install it. Since our project relies on third-party libraries, if you install it globally, the third-party UI library of the entire project cannot run! So we still choose to install `@vue/composition-api` to experience, so as to slowly transition to the latest version of vue3
## Vue 3.0 Composition-API Basic Features Experience ### setup function The `setup()` function is a new attribute specially provided for components in vue3, which is equivalent to the `created` function in the 2.x version. The component logic options of the previous version are now handled in this function. It provides a unified entry point for us to use the new features of vue3 `Composition API`. The **setup** function will be executed after **beforeCreate** and before **created** relative to 2.x ! For details, please refer to the following: | vue2.x | vue3 | | :--------------: | :-------------: | | ~~beforeCreate~~ | setup(replace) | | ~~created~~ | setup(replace) | | beforeMount | onBeforeMount | | mounted | onMounted | | beforeUpdate | onBeforeUpdate | | updated | onUpdated | | beforeDestroy | onBeforeUnmount | | destroyed | onUnmounted | | errorCaptured | onErrorCaptured | ### New hook In addition to the 2.x life cycle equivalent, the Composition API also provides the following debugging hooks: -`onRenderTracked` -`onRenderTriggered` Both hooks received the options of `DebuggerEvent` and `onTrack` and `onTrigger` observers: ```javascript export default { onRenderTriggered(e){ Debugger //Check which dependency caused the component to re-render } } ``` ### Dependency Injection `provider` and `inject` enable dependency injection similar to the 2.x `provide/inject` option. Both can only be called during the current active instance of `setup()`. ```javascript import { provide, inject } from '@vue/composition-api' const ThemeSymbol = Symbol() const Ancestor = { setup() { provide(ThemeSymbol, 'dark') } } const Descendent = { setup() { const theme = inject(ThemeSymbol, 'light' /* optional default value */) return { theme } } } ``` `inject` accepts an optional default value as the second parameter. If no default value is provided, and the property cannot be found in the Provide context, then `inject` returns `undefined`. **Inject responsive data** In order to maintain the responsiveness between the provided value and the injected value, you can use `ref` ```javascript // in the parent component const themeRef = ref('dark') provide(ThemeSymbol, themeRef) // in the component const theme = inject(ThemeSymbol, ref('light')) watchEffect(() => { console.log(`theme set to: ${theme.value}`) }) ``` 1. Because the `setup` function receives 2 formal parameters, the first is `initProps`, which is the value passed by the parent component! , The second parameter is a **context object** `setupContext`, the main attributes of this object are: ```javascript attrs: Object // equivalent to this.$attrs in vue 2.x emit: ƒ () // equivalent to this.$emit() isServer: false // Is it server-side rendering listeners: Object // equivalent to this.$listeners in vue2.x parent: VueComponent // equivalent to this.$parent in vue2.x refs: Object // equivalent to this.$refs in vue2.x root: Vue // This root is the globally unique instance object returned when we use newVue() in main.js. Be careful not to confuse this with this in the single file assembly slots: {} // equivalent to this.$slots in vue2.x ssrContext:{} // server-side rendering related ``` ⚠️**Note**: The `this` cannot be accessed in the `setup()` function, regardless of whether this `this` refers to the global vue object (ie: the global generated by using new in main.js The vue instance object), still refers to the object of the single file component. But what if we want to access the instance object of the current component? We can introduce the api of `getCurrentInstance`, and the return value is the instance of the current component! ```javascript import { computed, getCurrentInstance } from "@vue/composition-api"; export default { name: "svg-icon", props: { iconClass: { type: String, required: true }, className: { type: String } }, setup(initProps,setupContext) { const { ctx } = getCurrentInstance(); const iconName = computed(() => { return `#icon-${initProps.iconClass}`; }); const svgClass = computed(() => { if (initProps.className) { return "svg-icon " + initProps.className; } else { return "svg-icon"; } }); return { iconName, svgClass }; } }; ``` ### Ref automatically expand (unwrap) The `ref()` function is used to create a **reactive** **data object** according to the given value. The return value of the `ref()` function call is a wrapped object (RefImpl), There is only one `.value` property on this object. If we want to access the value of the object in the `setup` function, we can get it through `.value`, but if it is in the `