Top Related Projects
This is the repo for Vue 2. For Vue 3, go to https://github.com/vuejs/core
The library for web and native user interfaces.
Deliver web apps with confidence 🚀
Cybernetically enhanced web apps
⚛️ Fast 3kB React alternative with the same modern API. Components & Virtual DOM.
:fire: An extremely fast, React-like JavaScript library for building modern user interfaces
Quick Overview
Vue2-happyfri is a quiz game application built with Vue.js 2. It demonstrates how to create a simple yet engaging quiz game using Vue.js, incorporating state management with Vuex and routing with Vue Router.
Pros
- Provides a practical example of building a complete application with Vue.js 2
- Demonstrates the use of Vuex for state management in a real-world scenario
- Includes responsive design for mobile and desktop compatibility
- Offers a good starting point for developers learning Vue.js and related technologies
Cons
- Uses an older version of Vue.js (Vue 2) instead of the latest Vue 3
- Limited documentation and comments in the code, which may make it challenging for beginners to understand
- Lacks comprehensive test coverage
- The project hasn't been actively maintained or updated recently
Code Examples
- Vuex store setup:
import Vue from 'vue'
import Vuex from 'vuex'
import mutations from './mutations'
import actions from './action'
Vue.use(Vuex)
const state = {
level: '第一周',
itemNum: 1,
allTime: 0,
timer: '',
itemDetail: [],
answerid: {}
}
export default new Vuex.Store({
state,
actions,
mutations
})
- Vue component example (Home.vue):
<template>
<div class="home_container">
<div>
<span class="home_logo"></span>
<span class="home_name">Vue2-happyfri</span>
</div>
<div class="home_nav">
<router-link to="/item" class="btn btn-primary">开始答题</router-link>
</div>
</div>
</template>
<script>
export default {
name: 'home'
}
</script>
- Vuex action example:
export default {
addNum({ commit, state }, id) {
commit('REMBER_ANSWER', id);
if (state.itemNum < state.itemDetail.length) {
commit('ADD_ITEMNUM', 1);
}
},
// ... other actions
}
Getting Started
To run the project locally:
-
Clone the repository:
git clone https://github.com/bailicangdu/vue2-happyfri.git
-
Install dependencies:
cd vue2-happyfri npm install
-
Start the development server:
npm run dev
-
Open your browser and navigate to
http://localhost:8080
to view the application.
Competitor Comparisons
This is the repo for Vue 2. For Vue 3, go to https://github.com/vuejs/core
Pros of Vue
- Comprehensive framework with extensive documentation and ecosystem
- Larger community support and more frequent updates
- Suitable for both small and large-scale applications
Cons of Vue
- Steeper learning curve for beginners
- More complex setup and configuration for advanced features
- Potentially overwhelming for simple projects
Code Comparison
Vue (core library):
export function createApp(rootComponent, rootProps = null) {
const app = ensureRenderer().createApp(rootComponent, rootProps)
const { mount } = app
app.mount = (containerOrSelector) => {
// ...
}
return app
}
vue2-happyfri (component example):
export default {
name: 'itemcontainer',
data() {
return {
itemNum: 1,
itemDetail: [],
timer: '',
}
},
// ...
}
Summary
Vue is a full-fledged framework offering extensive features and community support, making it suitable for various project sizes. However, it may be more complex for beginners and simple applications. vue2-happyfri, on the other hand, is a specific project built with Vue 2, demonstrating a simpler structure and focused implementation for a particular use case. While Vue provides a comprehensive toolkit, vue2-happyfri showcases a practical application of Vue in a real-world scenario.
The library for web and native user interfaces.
Pros of React
- Larger ecosystem and community support
- More flexible and can be used for both web and mobile development
- Better performance for large-scale applications
Cons of React
- Steeper learning curve, especially for beginners
- Requires additional libraries for full functionality (e.g., routing, state management)
- More complex setup and configuration
Code Comparison
React:
import React from 'react';
function App() {
return <h1>Hello, World!</h1>;
}
export default App;
vue2-happyfri:
<template>
<div>
<h1>{{ message }}</h1>
</div>
</template>
<script>
export default {
data() {
return {
message: 'Hello, World!'
}
}
}
</script>
Additional Notes
- React is a more comprehensive library for building user interfaces, while vue2-happyfri is a specific Vue.js project.
- React uses JSX, which combines JavaScript and HTML-like syntax, while Vue uses a template-based approach.
- vue2-happyfri is built with Vue 2, which has a different syntax and structure compared to React.
- React's component-based architecture allows for more reusable and modular code.
- vue2-happyfri showcases Vue's simplicity and ease of use for smaller projects.
Deliver web apps with confidence 🚀
Pros of Angular
- Comprehensive framework with built-in features for large-scale applications
- Strong typing with TypeScript integration
- Robust CLI tools for project scaffolding and development
Cons of Angular
- Steeper learning curve compared to Vue.js
- More verbose and complex for small projects
- Larger bundle size, potentially impacting initial load times
Code Comparison
Angular component:
@Component({
selector: 'app-root',
template: `
<h1>{{ title }}</h1>
<button (click)="incrementCounter()">Count: {{ counter }}</button>
`
})
export class AppComponent {
title = 'Angular App';
counter = 0;
incrementCounter() {
this.counter++;
}
}
vue2-happyfri component:
<template>
<div>
<h1>{{ title }}</h1>
<button @click="incrementCounter">Count: {{ counter }}</button>
</div>
</template>
<script>
export default {
data() {
return {
title: 'Vue App',
counter: 0
}
},
methods: {
incrementCounter() {
this.counter++
}
}
}
</script>
The Angular example showcases TypeScript usage and decorators, while the Vue example demonstrates a more concise component structure. Angular's approach is more opinionated and structured, whereas Vue offers flexibility and simplicity for smaller projects like vue2-happyfri.
Cybernetically enhanced web apps
Pros of Svelte
- Smaller bundle sizes and better performance due to compile-time optimization
- Simpler, more intuitive syntax with less boilerplate code
- Built-in state management without the need for additional libraries
Cons of Svelte
- Smaller ecosystem and community compared to Vue.js
- Fewer third-party components and plugins available
- Steeper learning curve for developers coming from traditional frameworks
Code Comparison
Svelte component:
<script>
let count = 0;
function increment() {
count += 1;
}
</script>
<button on:click={increment}>
Clicks: {count}
</button>
Vue2-happyfri component:
<template>
<button @click="increment">
Clicks: {{ count }}
</button>
</template>
<script>
export default {
data() {
return { count: 0 };
},
methods: {
increment() {
this.count += 1;
}
}
};
</script>
Summary
Svelte offers a more modern approach to web development with its compile-time optimizations and simpler syntax. It excels in performance and bundle size reduction. However, vue2-happyfri, being based on Vue.js, benefits from a larger ecosystem and more widespread adoption. The choice between the two depends on project requirements, team expertise, and desired performance characteristics.
⚛️ Fast 3kB React alternative with the same modern API. Components & Virtual DOM.
Pros of Preact
- Smaller bundle size and faster performance due to its lightweight nature
- Closer to vanilla JavaScript, making it easier for developers familiar with standard web technologies
- Extensive compatibility with React ecosystem through preact-compat
Cons of Preact
- Smaller community and ecosystem compared to Vue.js
- Less comprehensive documentation and learning resources
- May require additional configuration for certain React-specific features
Code Comparison
vue2-happyfri (Vue.js):
<template>
<div>{{ message }}</div>
</template>
<script>
export default {
data() {
return {
message: 'Hello, Vue!'
}
}
}
</script>
Preact:
import { h, Component } from 'preact';
class App extends Component {
render() {
return <div>{this.props.message}</div>;
}
}
export default App;
The code comparison shows the difference in syntax and structure between Vue.js and Preact. Vue.js uses a template-based approach with separate script and template sections, while Preact follows a more React-like JSX syntax. Preact's code is more concise and closer to vanilla JavaScript, but Vue.js offers a clearer separation of concerns in its component structure.
:fire: An extremely fast, React-like JavaScript library for building modern user interfaces
Pros of Inferno
- Higher performance and smaller bundle size than Vue2-happyfri
- More flexible and lightweight, allowing for easier integration into existing projects
- Offers a virtual DOM implementation, which can lead to faster rendering in complex applications
Cons of Inferno
- Smaller community and ecosystem compared to Vue.js, which Vue2-happyfri is based on
- Steeper learning curve for developers familiar with Vue.js or React
- Less comprehensive documentation and fewer learning resources available
Code Comparison
Vue2-happyfri (Vue.js):
<template>
<div>{{ message }}</div>
</template>
<script>
export default {
data() {
return {
message: 'Hello, Vue!'
}
}
}
</script>
Inferno:
import { render } from 'inferno';
function MyComponent({ message }) {
return <div>{message}</div>;
}
render(<MyComponent message="Hello, Inferno!" />, document.getElementById('app'));
While both frameworks allow for component-based development, Inferno's syntax is more similar to React, using JSX and functional components. Vue2-happyfri, being a Vue.js project, uses Vue's template syntax and component structure. Inferno's approach may be more familiar to React developers, while Vue's template syntax can be easier for beginners to grasp.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
说æ
é常ç®åçä¸ä¸ªvue2 + vuexç项ç®ï¼æ´ä¸ªæµç¨ä¸ç®äºç¶ï¼éº»éè½å°ï¼äºèä¿±å ¨ï¼éåä½ä¸ºå ¥é¨ç»ä¹ ã
å¦æ对æ¨æ帮å©ï¼æ¨å¯ä»¥ç¹å³ä¸è§ "Star" æ¯æä¸ä¸ è°¢è°¢ï¼ ^_^
æè æ¨å¯ä»¥ "follow" ä¸ä¸ï¼æä¼ä¸æå¼æºæ´å¤çæ趣ç项ç®
å¦æé®é¢è¯·ç´æ¥å¨ Issues ä¸æï¼æè æ¨åç°é®é¢å¹¶æé常好ç解å³æ¹æ¡ï¼æ¬¢è¿ PR ð
å¼åç¯å¢ macOS 10.12.3 Chrome 56 nodejs 6.10.0
è¿ä¸ªé¡¹ç®ä¸»è¦ç¨äº vue2 + vuex çå ¥é¨ç»ä¹ ï¼å¦å¤æ¨èä¸ä¸ª vue2 æ¯è¾å¤æç大å项ç®ï¼è¦çäºvuejs大é¨åçç¥è¯ç¹ãç®å项ç®å·²ç»å®æãå°åå¨è¿é
项ç®è¿è¡ï¼nodejs 6.0+ï¼
# å
éå°æ¬å°
git clone https://github.com/bailicangdu/vue2-happyfri.git
# è¿å
¥æ件夹
cd vue2-happyfri
# å®è£
ä¾èµ
npm install æ yarn(æ¨è)
# å¼å¯æ¬å°æå¡å¨localhost:8088
npm run dev
# åå¸ç¯å¢
npm run build
æææ¼ç¤º
demoå°åï¼è¯·ç¨chromeææºæ¨¡å¼é¢è§ï¼
移å¨ç«¯æ«æä¸æ¹äºç»´ç
è·¯ç±é ç½®
import App from '../App'
export default [{
path: '/',
component: App,
children: [{
path: '',
component: r => require.ensure([], () => r(require('../page/home')), 'home')
}, {
path: '/item',
component: r => require.ensure([], () => r(require('../page/item')), 'item')
}, {
path: '/score',
component: r => require.ensure([], () => r(require('../page/score')), 'score')
}]
}]
é ç½®actions
import ajax from '../config/ajax'
export default {
addNum({ commit, state }, id) {
//ç¹å»ä¸ä¸é¢ï¼è®°å½çæ¡idï¼å¤ææ¯å¦æ¯æåä¸é¢ï¼å¦æä¸æ¯å跳转ä¸ä¸é¢
commit('REMBER_ANSWER', id);
if (state.itemNum < state.itemDetail.length) {
commit('ADD_ITEMNUM', 1);
}
},
//åå§åä¿¡æ¯
initializeData({ commit }) {
commit('INITIALIZE_DATA');
}
}
mutations
const ADD_ITEMNUM = 'ADD_ITEMNUM'
const REMBER_ANSWER = 'REMBER_ANSWER'
const REMBER_TIME = 'REMBER_TIME'
const INITIALIZE_DATA = 'INITIALIZE_DATA'
export default {
//ç¹å»è¿å
¥ä¸ä¸é¢
[ADD_ITEMNUM](state, payload) {
state.itemNum += payload.num;
},
//è®°å½çæ¡
[REMBER_ANSWER](state, payload) {
state.answerid[state.itemNum] = payload.id;
},
/*
è®°å½åé¢æ¶é´
*/
[REMBER_TIME](state) {
state.timer = setInterval(() => {
state.allTime++;
}, 1000)
},
/*
åå§åä¿¡æ¯ï¼
*/
[INITIALIZE_DATA](state) {
state.itemNum = 1;
state.allTime = 0;
},
}
å建store
import Vue from 'vue'
import Vuex from 'vuex'
import mutations from './mutations'
import actions from './action'
Vue.use(Vuex)
const state = {
level: '第ä¸å¨',
itemNum: 1,
allTime: 0,
timer: '',
itemDetail: [],
answerid: {}
}
export default new Vuex.Store({
state,
actions,
mutations
})
å建vueå®ä¾
import Vue from 'vue'
import VueRouter from 'vue-router'
import routes from './router/router'
import store from './store/'
Vue.use(VueRouter)
const router = new VueRouter({
routes
})
new Vue({
router,
store,
}).$mount('#app')
Top Related Projects
This is the repo for Vue 2. For Vue 3, go to https://github.com/vuejs/core
The library for web and native user interfaces.
Deliver web apps with confidence 🚀
Cybernetically enhanced web apps
⚛️ Fast 3kB React alternative with the same modern API. Components & Virtual DOM.
:fire: An extremely fast, React-like JavaScript library for building modern user interfaces
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot