How do I implement a html/css/js theme into Vue properly? - javascript

I got a bootstrap theme that consists of HTML, CSS and Javascript. Now, I want to implement it (or let's say make it functional) in Vue. I have my index.html file that contains the container and it works. Now, my theme does have an index.html file as well. I just thought I can copy the whole file into the Vue-index.html and add the div with the id "app" around the area that changes the content. But it does not work. Basically, Vue does not load any external css or js files even though I reference them correctly (with relative reference using the dot: ./assets/css/style.css). It works inside a .vue-file (i.e. component) but not inside the index.html. What do I do wrong?
Yep, beginner here.

When you put them inside your index.html they are not compiled.
You can read about it HERE

Your index.html is something called a target. Vue uses this file as a mounting point for the rest of the application, so it's kept relatively clean, most likely with just metadata and a DOM mounting point. It works by loading the index.html in the browser and then mounting your Vue application on top of it.
If you're trying to apply some styles to a Vue application/components, your best bet is to modify *.vue files inside the app source of your Vue project (typically, /your-project/src). They will contain snippets of relevant sections/components alongside their logic (JavaScript) and styles (CSS/Sass), provided your project uses Single-File Components format.
For future reference:
It's hard to offer a solution without knowing the structure of your project, what type of components you are using, or even having code samples to get an idea of how things are working inside.
We'd need more information to be able to help you more accurately, so maybe you could create a lightweight demo on an interactive platform like codesandbox.io?

Related

Add a separate HTML file into create-react-app

I know react is for Single Page Application. I have already build a complete application. I have a particular 3rd party integration that requires javascript and css files. I cannot add those external scripts as it breaks my entire application by overriding css and js.
I need to have a separate admin.html file which can have its own css and javascript tags. I do not want any conflict with my react app which renders on index.html
I tried to eject create-react-app and add a new admin.html.
https://github.com/facebook/create-react-app/issues/1084#issuecomment-568550609
But it uses only one page(index.html). This will not help me because I need completely a separate html file which I can import any javascript or css freely without any conflict on my index.html
Currently the possibility I thought was to create a separate react application just to render to this admin.html. So that there won't be any conflicts between javascript and css. But I want to know if there is an alternate way that I can achieve it in create-react-app. If so, simple example would be greatly appreciated.
PS: I need to redirect from one of components in my application to this new view admin.html with some data

How do i automatically import JS and scss files when i include a .php component? (not using frameworks)

I am a starting web developer. The company I work for makes relatively simple websites, some with blogs and/or products. We use our own CMS and don’t use a framework.
I am trying to improve the architecture/structure we use for websites. Which is currently done with a single stylesheet and a single JS file. Which is awful to work with for me because I can never find anything in these files.
So I started to separate these files into smaller scss and JS files. I’ve done some research.
And i’d like to work with components Like this (preferably the first one):
I think this would work well for me because i am working in those 3 files at the same time, and then i don’t have to open them from different locations. Is this a good way to structure websites?
When i include the .php file for the component i would like to have it automatically call upon the right JS and scss files. This way i could move the component to a different website include it and it would work.
Is this possible? Is this even the right way to think about it?
And if not how do i go about importing or compiling JS and scss/css?

Partial Implementation of create-react-app to a website

I'm currently developing a website/webapp (I don't really know the clear distinction between it) for my school project. Initially I was planning to develop entirely through just HTML/CSS and JS, however, my adviser told me to use react framework for parts of the pages instead of just doing it with Java for the sake of simplicity. This has been really messing me up since I have no background in web development and I'm confused in general.
I currently have all of the HTML pages styled with CSS, and I was able to transition part of the web-app to react using create-react-app. However, I have no clue how to connect these two.
I created the my-app folder inside the main directory which contains most of the HTML folders, but how would I go by to
1. Access the react app from the HTML page?
2. Access the HTML page in the main directory from the react app?
Following is my directory as a reference
mainDir
|_____bunch of html files
|_____css //contains all css files
|_____img // contains all images
|_____my-app
|____all the files created by create-react-app
Approaches I have tried:
- using the in the HTML pages in the main directory to jump to index.html in the my-app file to load the app
- changing the file path on the tag inside the App.js render() function of each class to something like ../../welcome.html which is the relative path to an HTML in the main directory.
Thank you for your help in advance. I'm welcome to any and all suggestions! If there isn't enough information to assess the situation, please let me know!
Checkout
This Example source code, from React.js: "Add React in One Minute" guide.
What is it?
It's a super bare-minimum implementation of React using:
1 x .html file
1 x .js file
Given your current setup, I'd say it's a lot simpler than trying to incorporate create-react-app.
Let me know if this helps; I'm happy to delete this if it's not useful.

Independent VueJS components with webpack?

I made some SPA using vuejs-templates/webpack and that's ok. But now I am developing a website, almost everything is static, so there's no need to be a SPA. I already made the pure html/css layout.
Now I will make some pages with forms and dynamic content, I would like to use vue components inside these pages.
Tell me which of this ideas is the best or give me a better option:
Multiple entries in webpack: I don't know very well how to do it, but I guess I can create a webpack project by scratch and render multiple entries that I include in the pages I want.
Use browserify: I didn't want to do this, but sounds like a good option... I could use vueify to render *.vue components
Use Nuxt: I never tried, but seems a good option too, I could make a "SPA" with SSR.
Tell me if you have another idea.
Thank you
Don't rule out just referencing Vue as a script file. No bundle, no compilation step. You lose single file components, but you can get something very like them by using js template literals. If your needs are simple and you don't want to impact on the rest of the site, this could be a fine solution.

Loading custom scripts into Vue.js components

I've decided to rewrite a web app using Vue.js but I'd like to start small and use my already working scripts for the main part of the app, while using Vue for other parts.
I'm looking into the Vue webpack template and I've tried to include multiple script tags into a component but vue gives me a warning that this can't be done.
I've successfully included the scripts into the main index.html and it's working but I think that's a really bad solution. What are some other ways to use Vue components with included js scripts?
Vue.js will work with any old scripts you have. If you are trying to "start small", just leave your old scripts on the page where they are, and start moving them slowly into components.
https://jsfiddle.net/crabbly/14kvkL6d/
You could start moving parts of the scripts into the ready method on your components, and start organizing them later into separate methods. Eventually it will be very organized and you will be using the full power of Vue.
https://jsfiddle.net/crabbly/9ux28qL9/
When using vue-loader and webpack, you will have to use module.export. Which shouldn't be hard also.
Start with smaller components.

Categories

Resources